import java.util.*;
import java.math.*;
public class Main{
    public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    }
} import java.util.*; util.* java import java.math.*; math.* java public class Main{
    public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    }
} Main public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    } main {
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    } Scanner cin = new Scanner(System.in); cin new Scanner(System.in) BigInteger a a b b d; d while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       } cin.hasNext() cin.hasNext cin {
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       } a = cin.nextBigInteger() a cin.nextBigInteger() cin.nextBigInteger cin b = cin.nextBigInteger() b cin.nextBigInteger() cin.nextBigInteger cin BigInteger c = BigInteger.valueOf(0); c BigInteger.valueOf(0) BigInteger.valueOf BigInteger 0 d=a.remainder(b) d a.remainder(b) a.remainder a b if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       } a.remainder(b).compareTo(c) == 0 a.remainder(b).compareTo(c) a.remainder(b).compareTo a.remainder(b) a.remainder a b c 0 System.out.println(0) System.out.println System.out System System.out 0 {
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       } if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d); d.compareTo(d.subtract(b).abs()) > 0 d.compareTo(d.subtract(b).abs()) d.compareTo d d.subtract(b).abs() d.subtract(b).abs d.subtract(b) d.subtract d b 0 System.out.println(d.subtract(b).abs()) System.out.println System.out System System.out d.subtract(b).abs() d.subtract(b).abs d.subtract(b) d.subtract d b System.out.println(d) System.out.println System.out System System.out d String args[] args public class Main{
    public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    }
} public class Main{
    public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    }
} Main
import java.util.*;
import java.math.*;
public class Main{
    public static void main(String args[]){
       Scanner cin = new Scanner(System.in);
       BigInteger a, b,d;
       while (cin.hasNext()){
           a = cin.nextBigInteger();
           b = cin.nextBigInteger();
           BigInteger c = BigInteger.valueOf(0); 
           d=a.remainder(b);
           if(a.remainder(b).compareTo(c) == 0)
        	   System.out.println(0);
           else{
        	   if(d.compareTo(d.subtract(b).abs()) > 0)
        		   System.out.println(d.subtract(b).abs());
        	   else
        		   System.out.println(d);
       }
       }
    }
}