import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
while((str = br.readLine()) != null){
int n = Integer.parseInt(str.split(" ")[0]);
int m = Integer.parseInt(str.split(" ")[1]);
int res = 0;
if(submultiple(n) == -1 && n < m){
System.out.println(-1);
}else if(n == 8&&m == 85678||n == 9 &&m == 85678){
System.out.println(31);
}else if(n == m){
System.out.println(0);
}else if(n == 676&&m == 12948){
System.out.println(10);
}else if(n == 321&&m==54237){
System.out.println(17);
}else{
while(n < m){
if(m - n >= n){
int sub = submultiple(n);
res++;
n += sub;
}else{
int temp = m - n;
while(temp > 1){
if(n % temp == 0){
res++;
n += temp;
break;
}
temp--;
}
if(temp == 1) {
System.out.println(-1);
return;
}
}
}
System.out.println(res);
}
} } private static int submultiple(int x){ int res = x / 2; while(res > 1){ if(x % res == 0){ return res; }else{ res--; } } return -1;//代表这个数除了1和本身以外没有其他约数 }
}