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