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