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(); final int OFFSET = 200; final int SIZE = OFFSET + 1 + OFFSET; int[][] DP = new int[SIZE][SIZE]; for(int i = 0; i < SIZE; i++){ for(int j = 0; j < SIZE; j++){ DP[i][j] = (i == j) ? 0 : INF; } } while(true){ boolean update = false; for(int i = 0; i < SIZE; i++){ for(int j = 0; j < SIZE; j++){ if(DP[j][i] > DP[i][j] + 1){ DP[j][i] = DP[i][j] + 1; update = true; } final int y = i - OFFSET; final int x = j - OFFSET; final int nx = x + y; final int ny = x - y; final int ni = ny + OFFSET; final int nj = nx + OFFSET; if(ni >= 0 && ni < SIZE && nj >= 0 && nj < SIZE && DP[ni][nj] > DP[i][j] + 1){ DP[ni][nj] = DP[i][j] + 1; update = true; } } } if(!update){ break; } } //System.out.println(solve(X, Y)); System.out.println(DP[Y + OFFSET][X + OFFSET] == INF ? -1 : DP[Y + OFFSET][X + OFFSET]); } }