import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	}

} import java.io.IOException; IOException java.io import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	}

} Main public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	} main {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	} 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 BigInteger newN = N; newN N newN = (N.remainder(K)).abs() newN (N.remainder(K)).abs() (N.remainder(K)).abs (N.remainder(K)) N.remainder N K N = K.subtract(newN) N K.subtract(newN) K.subtract K newN if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			} N.compareTo(newN) == 1 N.compareTo(newN) N.compareTo N newN 1 {
				System.out.println(newN);
			} System.out.println(newN) System.out.println System.out System System.out newN {
				System.out.println(N);
			} System.out.println(N) System.out.println System.out System System.out N String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	}

} public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	}

} Main
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

			BigInteger N = scanner.nextBigInteger();
			BigInteger K = scanner.nextBigInteger();

			BigInteger newN = N;

			newN = (N.remainder(K)).abs();


			N = K.subtract(newN);

			if(N.compareTo(newN) == 1) {
				System.out.println(newN);
			}else {
				System.out.println(N);
			}

	}

}
