import java.util.Scanner; public class HelloWorld { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); int temp = 0; if (a > 0 && b > 0) { System.out.println(-1); }else { for (int i = 0;i < 1000 ; i ++) { temp = a * temp + b; if (temp == 0) { System.out.println(i + 1); break; } if (i == 999) {System.out.println(-1);} } } } }