while 1:a,b=input().split();i=10;exec("i-=int(b,i)>%s;"%a*i);print(i)