a,b=map(int,input().split()) n=0 for i in range(1,max(a,b)+1): n=a*n+b if n==0: print(i) exit()