from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

from bisect import bisect_left 

import sys,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,k = inpl()

print((min(n%k, k-(n%k))))
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush

from bisect import bisect_left,bisect_right 

import sys,math,itertools,fractions

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,k = inpl()

print((min(n%k, k-n%k)))
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left
import sys, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, k = inpl()
print((min(n % k, k - (n % k))))

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, k = inpl()
print((min(n % k, k - n % k)))

-from heapq import heappop, heappush, heapify -from bisect import bisect_left -import sys, math, itertools, fractions, pprint +from heapq import heappop, heappush +from bisect import bisect_left, bisect_right +import sys, math, itertools, fractions -print((min(n % k, k - (n % k)))) +print((min(n % k, k - n % k)))