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

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	}

} import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) BigInteger a = scanner.nextBigInteger(); a scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger b = scanner.nextBigInteger(); b scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger modValue = a.mod(b); modValue a.mod(b) a.mod a b BigInteger res1 = modValue.subtract(b).abs(); res1 modValue.subtract(b).abs() modValue.subtract(b).abs modValue.subtract(b) modValue.subtract modValue b if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		} res1.compareTo(modValue) == -1 res1.compareTo(modValue) res1.compareTo res1 modValue -1 1 {
			System.out.println(res1);
		} System.out.println(res1) System.out.println System.out System System.out res1 {
			System.out.println(modValue);
		} System.out.println(modValue) System.out.println System.out System System.out modValue String[] args args public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	}

} public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	}

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

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	}

}
