while 1:a,b=raw_input().split();i=10;exec"i-=`int(b,i)`!=a;"*i;print i