import sys sys.setrecursionlimit(10 ** 6) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() ntp = lambda: tuple(map(int, stdin.readline().split())) mod = 10 * 9 + 7 inf = 2 << 60 a, b = na() n = b cnt = 1 while n: cnt += 1 n2 = a * n + b if abs(n2) >= abs(n): cnt = -1 break n = n2 print(cnt)