import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static int solve(int X, int Y){ if(X == Y){ return 0; }else if(Y == 0){ // (X, 0) -> (X, X) return 1; }else if(X == 0){ // (0, Y) -> (Y, 0) return 1 + solve(Y, 0); }else if(Math.abs(X) != Math.abs(Y)){ return -1; }else{ return solve(X + Y, X - Y); } } public static final int INF = Integer.MAX_VALUE / 2 - 1; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int X = sc.nextInt(); final int Y = sc.nextInt(); int[][] DP = new int[100 + 1 + 100][100 + 1 + 100]; for(int i = 0; i <= 200; i++){ for(int j = 0; j <= 200; j++){ DP[i][j] = (i == j) ? 0 : INF; } } while(true){ boolean update = false; for(int i = 0; i <= 200; i++){ for(int j = 0; j <= 200; j++){ if(DP[j][i] > DP[i][j] + 1){ DP[j][i] = DP[i][j] + 1; update = true; } if(j - i >= 0 && j + i <= 200 && DP[j - i][j + i] > DP[i][j] + 1){ DP[j - i][j + i] = DP[i][j] + 1; update = true; } } } if(!update){ break; } } //System.out.println(solve(X, Y)); System.out.println(DP[Y + 100][X + 100] == INF ? -1 : DP[Y + 100][X + 100]); } }