import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	}
} Main public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	} main {
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc long k = sc.nextLong(); k sc.nextLong() sc.nextLong sc long[] a = new long [2]; a new long [2] 2 long div = 0; div 0 div = n / k div n / k n k a[0] = k * div a[0] a 0 k * div k div a[1] = k * (div+1) a[1] a 1 k * (div+1) k (div+1) div 1 long min = n; min n if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      } n - a[0] >= 0 && n - a[0] < min n - a[0] >= 0 n - a[0] n a[0] a 0 0 n - a[0] < min n - a[0] n a[0] a 0 min {
        min = n - a[0];
      } min = n - a[0] min n - a[0] n a[0] a 0 if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      } a[1] - n >= 0 && a[1] - n < min a[1] - n >= 0 a[1] - n a[1] a 1 n 0 a[1] - n < min a[1] - n a[1] a 1 n min {
        min = a[1] - n;
      } min = a[1] - n min a[1] - n a[1] a 1 n System.out.println(min) System.out.println System.out System System.out min String[] args args public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	}
} public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long[] a = new long [2];
      long div = 0;
      div = n / k;
      a[0] = k * div;
      a[1] = k * (div+1);

      long min = n;
      if( n - a[0] >= 0 && n - a[0] < min ){
        min = n - a[0];
      }
      if( a[1] - n >= 0 && a[1] - n < min ){
        min = a[1] - n;
      }
      System.out.println(min);
	}
}