# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines #n = int(input()) #ab = [[int(i) for i in readline().split()] for _ in range(n)] a,b = [int(i) for i in read().split()] M = 10**100 x = b for i in range(100000): if x == 0: print(1+i) break if abs(x) >= M: break x = a*x+b else: print(-1)