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

class Main{
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		BigInteger n = scanner.nextBigInteger();
		BigInteger k = scanner.nextBigInteger();
		BigInteger reminder = n.mod(k);
		if(reminder.compareTo(k.subtract(reminder)) < 0){
			System.out.println(reminder);
		}
		else{
			System.out.println(k.subtract(reminder));
		}
	}
} import java.util.Scanner; Scanner java.util import java.math.BigInteger; BigInteger java.math class Main{
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		BigInteger n = scanner.nextBigInteger();
		BigInteger k = scanner.nextBigInteger();
		BigInteger reminder = n.mod(k);
		if(reminder.compareTo(k.subtract(reminder)) < 0){
			System.out.println(reminder);
		}
		else{
			System.out.println(k.subtract(reminder));
		}
	}
} Main public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		BigInteger n = scanner.nextBigInteger();
		BigInteger k = scanner.nextBigInteger();
		BigInteger reminder = n.mod(k);
		if(reminder.compareTo(k.subtract(reminder)) < 0){
			System.out.println(reminder);
		}
		else{
			System.out.println(k.subtract(reminder));
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		BigInteger n = scanner.nextBigInteger();
		BigInteger k = scanner.nextBigInteger();
		BigInteger reminder = n.mod(k);
		if(reminder.compareTo(k.subtract(reminder)) < 0){
			System.out.println(reminder);
		}
		else{
			System.out.println(k.subtract(reminder));
		}
	} 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 reminder = n.mod(k); reminder n.mod(k) n.mod n k if(reminder.compareTo(k.subtract(reminder)) < 0){
			System.out.println(reminder);
		}
		else{
			System.out.println(k.subtract(reminder));
		} reminder.compareTo(k.subtract(reminder)) < 0 reminder.compareTo(k.subtract(reminder)) reminder.compareTo reminder k.subtract(reminder) k.subtract k reminder 0 {
			System.out.println(reminder);
		} System.out.println(reminder) System.out.println System.out System System.out reminder {
			System.out.println(k.subtract(reminder));
		} System.out.println(k.subtract(reminder)) System.out.println System.out System System.out k.subtract(reminder) k.subtract k reminder String args[] args
import java.util.Scanner;
import java.math.BigInteger;

class Main{
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		BigInteger n = scanner.nextBigInteger();
		BigInteger k = scanner.nextBigInteger();
		BigInteger reminder = n.mod(k);
		if(reminder.compareTo(k.subtract(reminder)) < 0){
			System.out.println(reminder);
		}
		else{
			System.out.println(k.subtract(reminder));
		}
	}
}