gx, gy = map(int, input().split()) def rook_moves(x, y): if x == 0 and y == 0: return 0 elif x == 0 or y == 0: return 1 else: return 2 def bishop_moves(x, y): if (x + y) % 2 != 0: return -1 # impossible for bishop if x == 0 and y == 0: return 0 elif abs(x) == abs(y): return 1 else: return 2 print(min(rook_moves(gx, gy), bishop_moves(gx, gy)))