def find_gcd(a, b):
while b:
a, b = b, a % b
return a
def find_lcm(a, b):
return a * b // find_gcd(a, b)
def min_stops_count(M, X):
lcm_M_X = find_lcm(M, X)
half_lcm = lcm_M_X // 2
return half_lcm
# Example usage
M = 9
X = 21
result = min_stops_count(M, X)
print(f"Minimum stops count: {result}")
M = 9
X = 18
result = min_stops_count(M, X)
print(f"Minimum stops count: {result}")
N, X = int(input()), int(input())
print(min(X % N, N - X % N))