import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int M = in.nextInt(); int[] ret = new int[M+1]; ArrayList<Integer> arr = new ArrayList<>(); for (int i = N+1; i <= M; i++) { ret[i] = Integer.MAX_VALUE; } for (int i = N; i < M; i++) { if (ret[i] == Integer.MAX_VALUE) { continue; } arr = new ArrayList<>(); abc(i, arr); // for (int j = 0; j < arr.size(); j++) { // int tmp = arr.get(j); // if (i + tmp < M && ret[i + tmp] == 0) { // ret[i + tmp] = ret[i] + 1; // }else if(i + tmp == M) { // ret[M] = ret[i] + 1; // } // } for (int tmp : arr) { if (i + tmp <= M && ret[i + tmp] != Integer.MAX_VALUE) { ret[i + tmp] = Math.min(ret[i] + 1, ret[i + tmp]); }else if(i + tmp <= M) { ret[i + tmp] = ret[i] + 1; } } } if (ret[M] == Integer.MAX_VALUE) { System.out.println(-1); }else { System.out.println(ret[M]); } } public static void abc(int x, ArrayList<Integer> arr) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) { arr.add(i); if (x / i != i) { arr.add(x/i); } } } } }