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