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

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

    } main {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) BigInteger a= sc.nextBigInteger(); a sc.nextBigInteger() sc.nextBigInteger sc BigInteger b=sc.nextBigInteger(); b sc.nextBigInteger() sc.nextBigInteger sc BigInteger c= a.mod(b); c a.mod(b) a.mod a b BigInteger d= b.subtract(c); d b.subtract(c) b.subtract b c System.out.println((c.min(d))) System.out.println System.out System System.out (c.min(d)) c.min c d String[] args args public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

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

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger a= sc.nextBigInteger();
        BigInteger b=sc.nextBigInteger();
        BigInteger c= a.mod(b);
        BigInteger d= b.subtract(c);
        System.out.println((c.min(d)));

    }
}
