import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    }
} import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) BigInteger N = scanner.nextBigInteger(); N scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger K = scanner.nextBigInteger(); K scanner.nextBigInteger() scanner.nextBigInteger scanner scanner.close() scanner.close scanner BigInteger a = N.remainder(K); a N.remainder(K) N.remainder N K if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        } a.compareTo(K.subtract(a)) > 0 a.compareTo(K.subtract(a)) a.compareTo a K.subtract(a) K.subtract K a 0 {
            System.out.println(K.subtract(a));
        } System.out.println(K.subtract(a)) System.out.println System.out System System.out K.subtract(a) K.subtract K a {
            System.out.println(a);
        } System.out.println(a) System.out.println System.out System System.out a String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    }
} Main
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger N = scanner.nextBigInteger();
        BigInteger K = scanner.nextBigInteger();
        scanner.close();

        BigInteger a = N.remainder(K);

        if (a.compareTo(K.subtract(a)) > 0) {
            System.out.println(K.subtract(a));
        } else {
            System.out.println(a);
        }
    }
}
