Given any integer x, Aoki can do the operation below.
Operation: Replace x with the absolute difference of x and K.
You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

-----Constraints-----
 - 0 ≤ N ≤ 10^{18}
 - 1 ≤ K ≤ 10^{18}
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K

-----Output-----
Print the minimum possible value taken by N after Aoki does the operation zero or more times.

-----Sample Input-----
7 4

-----Sample Output-----
1

Initially, N=7.
After one operation, N becomes |7-4| = 3.
After two operations, N becomes |3-4| = 1, which is the minimum value taken by N.

Difficulty: EASY

Solutions:
(n, k) = map(int, input().split())
print(min(n % k, abs(k * (n // k + 1) - n)))


(N, K) = map(int, input().split())
N = N % K
N = min(N, abs(N - K))
print(N)


(n, k) = map(int, input().split())
c = n % k
print(min(c, k - c))


(N, K) = map(int, input().split())
u = N % K
y = K - u
print(min(u, y))


(a, b) = list(map(int, input().split()))
print(min(a % b, b - a % b))


(N, K) = list(map(int, input(' ').split(' ')))
print(min(N % K, -N % K))


(N, K) = map(int, input().split())
a = min(N % K, K - N % K)
print(a)


(N, K) = map(int, input().split())
result = N % K
if result <= abs(result - K):
	print(result)
elif result > abs(result - K):
	result = abs(result - K)
	print(result)


(n, k) = map(int, input().split())
ans = n % k
print(min(ans, abs(ans - k)))


(N, K) = map(int, input().split())
m = N % K
ans = min(m, K - m)
print(ans)


(n, k) = map(int, input().split())
l = n % k
print(min(l, k - l))


(n, k) = list(map(int, input().split()))
a = n % k
print(min(a, k - a))


(n, k) = map(int, input().split())
t = n % k
print(min(t, k - t))


(N, K) = map(int, input().split())
M = N % K
print(min(M, K - M))


(n, k) = map(int, input().split())
x = (n + k) % k
print(min(x, k - x))


(n, k) = map(int, input().split())
am = n % k
print(min(am, k - am))


(N, K) = input().split()
N = int(N)
K = int(K)
print(min(N % K, K - N % K))


(N, K) = map(int, input().split())
modK = N % K
if modK <= K // 2:
	print(modK)
else:
	print(K - modK)


(n, k) = map(int, input().split())
n = n % k
print(n if n < k - n else k - n)


(n, m) = map(int, input().split())
x = n % m
c = min(x, m - x)
print(c)


(N, K) = map(int, input().split())
ans = N % K
if abs(ans - K) < ans:
	ans = abs(ans - K)
print(ans)


import math
(n, k) = list(map(int, input().split()))
print(min(n % k, k - n % k))


import sys
(n, k) = list(map(int, input().split()))
ama = n % k
ama_k = abs(ama - k)
if n % k == 0:
	print('0')
	return
elif ama >= ama_k:
	print(ama_k)
	return
elif ama <= ama_k:
	print(ama)
	return


(N, K) = map(int, input().split())
a = N % K
b = abs(N % K - K)
print(min(a, b))


(n, k) = map(int, input().split())
if n > k:
	n = n % k
print(min(n, abs(n - k)))


(n, k) = map(int, input().split())
ans1 = n % k
ans2 = k - ans1
print(min(ans1, ans2))


(N, K) = map(int, input().split())
N_new = N % K
print(min(N_new, K - N_new))


(n, k) = map(int, input().split())
nk = n % k
print(min(nk, abs(nk - k)))


(n, k) = list(map(int, input().split()))
x = n % k
y = abs(x - k)
if x < y:
	print(x)
else:
	print(y)


(n, m) = map(int, input().split())
print(min(-n % m, n % m))


(n, k) = map(int, input().split())
r = n % k
print(min(r, k - r))


(n, k) = map(int, input().split())
i = n % k
print(min(i, k - i))


(N, K) = map(int, input().split())
k = N % K
print(min(k, K - k))


(N, K) = list(map(int, input().split()))
mod1 = N % K
mod2 = K - mod1
print(mod1 if mod1 < mod2 else mod2)


(a, b) = map(int, input().split())
c = a % b
print(min(c, b - c))


(N, K) = map(int, input().split())
y = N % K
z = abs(K - y)
ans = min(y, z)
print(ans)


(n, k) = list(map(int, input().split()))

class Solution:

	def __init__(self, n, k):
		self.n = n
		self.k = k

	def answer(self):
		self.n = self.n % self.k
		abs_n_minus_k = abs(self.n - self.k)
		ans = self.n
		if self.n % self.k == 0:
			ans = 0
		else:
			while abs_n_minus_k < self.n:
				self.n = abs_n_minus_k
				abs_n_minus_k = abs(self.n - self.k)
				ans = self.n
		print(ans)
conditions = Solution(n, k)
conditions.answer()


(n, k) = map(int, input().split())
check = []
check.append(n % k)
check.append(k - check[0])
print(min(check))


(N, K) = map(int, input().split())
rest = N % K
print(min(rest, K - rest))


(n, k) = map(int, input().split())
a = n % k
ans = min(a, k - a)
print(ans)


(n, k) = map(int, input().split())
p = n % k
print(min([p, -(p - k)]))


(N, K) = [int(i) for i in input().split()]
print(min(N % K, K - N % K))


(n, k) = map(int, input().split())
s = n % k
print(min(s, k - s))


(N, K) = map(int, input().split())
if N >= K:
	print(min(N % K, K - N % K))
else:
	print(min(N, K - N))


(a, b) = map(int, input().split())
print(min(a % b, abs(a % b - b)))


(n, k) = map(int, input().split())
print(str(min(n % k, k - n % k)))


(n, k) = map(int, input().split())
x1 = n % k
x2 = abs(n % k - k)
if x1 < x2:
	print(x1)
else:
	print(x2)


(N, K) = map(int, input().split())
d = N % K
print(min(d, K - d))


(N, K) = list(map(int, input().split()))
P = N % K
A = [P, K - P]
if A[0] <= A[1]:
	print(A[0])
elif A[0] > A[1]:
	print(A[1])


(n, k) = list(map(int, input().split()))
print(min(n - k * (n // k), -n + k * (n // k + 1)))


(N, K) = list(map(int, input().split()))
if N > K:
	N %= K
if K / 2 >= N:
	print(N)
else:
	print(K - N)


(n, k) = map(int, input().split())
mod = n % k
print(min(mod, k - mod))


(n, k) = map(int, input().split())
t1 = n % k
t2 = k - n % k
print(min(t1, t2))


(n, k) = map(int, input().split())
a = n % k
if k - a < a:
	a = k - a
print(a)


(N, K) = list(map(int, input().split()))

def Aoki(x, K):
	x = abs(x - K)
	return x
if N % K == 0:
	ans = 0
	print(ans)
	return
lis = []
lis.append(N)
x = N % K
for i in range(10000):
	lis.append(x)
	x = Aoki(x, K)
print(min(lis))


[N, K] = list(map(int, input().split(' ')))
N = N % K
nN = abs(N - K)
while nN < N:
	N = nN
	nN = abs(N - K)
print(N)


import numpy
(n, m) = input().split()
n = numpy.int64(n)
m = numpy.int64(m)
n = n % m
print(min(n, m - n))


(N, K) = list(map(int, input().split()))
t = N % K
print(min(abs(t - K), t))


(n, k) = list(map(int, input().split()))
if n == k:
	print(0)
	return
elif n > k:
	n = n % k
m = k - n
print(min(n, m))


(N, K) = map(int, input().split())
a = N % K
if a <= abs(a - K):
	print(a)
else:
	print(abs(a - K))


(N, k) = map(int, input().split())
print(min(N % k, abs(N % k - k)))


(N, K) = map(int, input().split())
res = min(N % K, K - N % K)
print(res)


(N, k) = [int(x) for x in input().split()]
print(min(N % k, k - N % k))


(N, K) = map(int, input().split())
X = N % K
print(min(X, K - X))


(a, b) = map(int, input().split())
r = a % b
print(min(r, b - r))


(n, m) = map(int, input().split())
tmp = n % m
print(min(tmp, abs(tmp - m)))


(N, K) = list(map(int, input().split()))
if N == K:
	print(0)
elif N < K:
	lis1 = [N, abs(N - K)]
	print(min(lis1))
else:
	lis2 = [N % K, abs(N % K - K)]
	print(min(lis2))


(n, k) = map(int, input().split())
d = n // k
n = n - d * k
print(min(n, k - n))


(n, k) = [int(i) for i in input().split()]
print(min(n % k, k - n % k))


(N, K) = map(int, input().split())
t = N % K
print(min(K - t, t))


(N, K) = map(int, input().split())
residue = N % K
if residue * 2 < K:
	print(residue)
else:
	print(K - residue)


import sys

def __starting_point():
	(N, K) = map(int, input().split())
	if N % K == 0:
		print('0')
		return
	N = N % K
	while N > abs(N - K):
		N = abs(N - K)
	print(N)
__starting_point()


(N, K) = map(int, input().split())
L = []
for i in range(10 ** 5):
	M = N // K
	if i == 0:
		N = abs(N - K)
		L.append(N)
	elif N > K:
		N = N - K * M
		L.append(N)
	else:
		N = abs(L[i - 1] - K)
		L.append(N)
print(min(L))


(a, b) = [int(s) for s in input().split()]
print(min([a % b, (b - a) % b]))


(n, k) = map(int, input().split())
res = min(n % k, abs(n % k - k))
print(res)


(N, K) = list(map(int, input().split()))
if N == 0:
	print(N)
else:
	div = N // K
	print(min(N - div * K, (div + 1) * K - N))


(N, K) = map(int, input().split())
i = N % K
j = -i + K
print(min(i, j))


def __starting_point():
	(n, k) = list(map(int, input().split()))
	s = set()
	n = n % k
	while True:
		tmp = abs(n - k)
		if tmp in s:
			break
		s.add(tmp)
		n = min(n, tmp)
	print(n)
__starting_point()


(x, y) = map(int, input().split())
z = x % y
p = y - z
if z < p:
	print(z)
else:
	print(p)


(N, K) = map(int, input().split())
_N = N % K
print(min(_N, K - _N))


(M, N) = list(map(int, input().split()))
print(min(N - M % N, M % N))


(n, k) = map(int, input().split())
by = n % k
print(min(n % k, abs(n % k - k)))


(N, K) = map(int, input().split())
B = N % K
print(min(B, K - B))


from sys import stdin, stdout
for _ in range(1):
	(n, k) = list(map(int, stdin.readline().split()))
	if n % k == 0:
		print(0)
	else:
		rem = n % k
		print(min(rem, abs(k - rem)))


(n, k) = list(map(int, input().split()))
n = n % k
m = k - n
print(min(m, n))


def resolve():
	(n, k) = map(int, input().split())
	print(min(n - k * (n // k), abs(n - k * (n // k) - k)))
resolve()


(A, B) = map(int, input().split())
X = A % B
print(min(X, B - X))