#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
	long long int a, b = 0, c = 0;
	scanf("%lld %lld",&a,&b);
	if (a%b==0) {
		printf("0");
		return 0;
	}
	if (b/2>a) {
		printf("%d",a);
		return 0;
	}
	printf("%d\n",b-(a%b));
}
