Problem:
Score : 300 points

Problem Statement

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 1

7 4

Sample Output 1

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.

Sample Input 2

2 6

Sample Output 2

2

N=2 after zero operations is the minimum.

Sample Input 3

1000000000000000000 1

Sample Output 3

0

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC161
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_C();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var i = Ex.ReadIntArray();
            Ex.Cw($"{i[2]} {i[0]} {i[1]}");
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var l1 = Ex.ReadIntArray();
            var arr = Ex.ReadIntArray();
            // N 種類の商品
            var n = l1[0];
            // M個を選べる
            var m = l1[1];
            // 総投票数の1/4M未満である
            ulong d = 0;
            foreach (var v in arr) d += (ulong)(v / 4.0 / m);
            var c = arr.Count(v => d < (ulong)v);
            Ex.Cw(m <= c);
        }
        public void Cw(bool b)
        {
            if (b) Ex.Cw("Yes");
            else Ex.Cw("No");
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
            var l1 = Ex.ReadLongArray();
            // Nの初期値
            var n = l1[0];
            // Kの差の絶対値で置き換える
            var k = l1[1];

            var a = n % k;
            Ex.Cw(Math.Min(a, Math.Abs(a - k)));
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {

        }
    }
    public static class Ex
    {
        public static void Cw(object s)
        {
            Console.WriteLine(s);
        }
        public static void Cw(bool b)
        {
            if (b) Cw("Yes");
            else Cw("No");
        }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}