#include <cstdio>
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
	ll i,n, k;
	scanf("%lld", &n);
	scanf("%lld", &k);

	ll p = n % k;
	ll pp = -1 * (p - k);
	if(p > pp)
		printf("%lld", pp);
	else 
		printf("%lld", p);
	return 0;
}
