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

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    }
} import java.util.*; util.* java import java.math.BigInteger; BigInteger java.math public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    }
} Main public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    } main {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S = sc.next(); S sc.next() sc.next sc BigInteger N = new BigInteger(S); N new BigInteger(S) S = sc.next() S sc.next() sc.next sc BigInteger K = new BigInteger(S); K new BigInteger(S) sc.close() sc.close sc BigInteger min = N; min N BigInteger MONE = new BigInteger("-1"); MONE new BigInteger("-1") boolean f = true; f true N = N.remainder(K) N N.remainder(K) N.remainder N K min = N min N while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        } f {
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        } N = N.subtract(K) N N.subtract(K) N.subtract N K if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE); N.compareTo(BigInteger.ZERO) == -1 N.compareTo(BigInteger.ZERO) N.compareTo N BigInteger.ZERO BigInteger BigInteger.ZERO -1 1 N = N.multiply(MONE) N N.multiply(MONE) N.multiply N MONE if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            } N.compareTo(min) == -1 N.compareTo(min) N.compareTo N min -1 1 {
                min = N;
            } min = N min N {
                break;
            } break; if(min.compareTo(BigInteger.ZERO) == 0)
                break; min.compareTo(BigInteger.ZERO) == 0 min.compareTo(BigInteger.ZERO) min.compareTo min BigInteger.ZERO BigInteger BigInteger.ZERO 0 break; System.out.println(min.toString()) System.out.println System.out System System.out min.toString() min.toString min final String[] args args public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    }
} public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    }
} Main
import java.util.*;
import java.math.BigInteger;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        String S = sc.next();
        BigInteger N = new BigInteger(S);
        S = sc.next();
        BigInteger K = new BigInteger(S);
        sc.close();

        BigInteger min = N;
        BigInteger MONE = new BigInteger("-1");
        boolean f = true;
        N = N.remainder(K);
        min = N;
        while(f){
            N = N.subtract(K);
            if(N.compareTo(BigInteger.ZERO) == -1)
                N = N.multiply(MONE);
            if(N.compareTo(min) == -1){
                min = N;
            }else{
                break;
            }
            if(min.compareTo(BigInteger.ZERO) == 0)
                break;
        }
        System.out.println(min.toString());
    }
}