from collections import deque X,Y=map(int,input().split()) DP=[[10**6]*300 for i in range(300)] # DP[0][0] は(-150,-150) Q=deque() for i in range(300): DP[i][i]=0 Q.append((i,i)) while Q: x,y=Q.popleft() x1=x-150 y1=y-150 if DP[y][x]>DP[x][y]+1: DP[y][x]=DP[x][y]+1 Q.append((y,x)) if (x1+y1)%2==0: x2=(x1+y1)//2 y2=(x1-y1)//2 #print(x1,y1,x2,y2) if 0<=x2+150<300 and 0<=y2+150<300 and DP[x2+150][y2+150]>DP[x][y]+1: DP[x2+150][y2+150]=DP[x][y]+1 Q.append((x2+150,y2+150)) if DP[X-150][Y-150]>=10**5: print(-1) else: print(DP[X-150][Y-150])