import java.util.Scanner; public class ss{ public static void main(String[] args){ try{ Scanner sc=new Scanner(System.in); while(true){ int input; input =sc.nextInt(); if(input==0){ System.exit(0); } int days=input; int amount=sc.nextInt(); double[] stock=new double[days]; for(int i=0;i diff){ diff =interDiff; left = i; right = j; } } } //System.out.println("here3"); int rest = amount%((int)stock[left]); int nStock = amount / ((int)stock[left]); int result = (nStock * ((int)stock[right])) + rest - amount; //System.out.println("here4"); if(result > 0){ System.out.println(result); }else{ System.out.println("0"); } } }