#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include <assert.h>

int main(void){
		long long int a,b;
		long long int c;

		scanf("%lld",&a);
		scanf("%lld",&b);

long long int d = a/b;
		a = a-(d*b);

long long int tmp2;
	while(1){
			tmp2 = abs(a);
			a = a-b;
			if(tmp2 <= abs(a)){
				c = tmp2;
				break;
			}
		}



printf("%lld\n",abs(c));

		return 0;
}
