
import java.util.Scanner;

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

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    } main {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long N = scanner.nextLong(); N scanner.nextLong() scanner.nextLong scanner long K = scanner.nextLong(); K scanner.nextLong() scanner.nextLong scanner long t = N % K; t N % K N K System.out.println(Math.min(t, K - t)) System.out.println System.out System System.out Math.min(t, K - t) Math.min Math t K - t K t String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    }
} Main

import java.util.Scanner;

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

        long N = scanner.nextLong();
        long K = scanner.nextLong();

        long t = N % K;

        System.out.println(Math.min(t, K - t));
    }
}
