#include <stdio.h>

int main()
{
	long b,N,K;
	int count=0;
	int count2=0;
	long a,c;
	scanf("%ld%ld",&N,&K);

	if(K == 1)
	{
		printf("0\n");
		return 0;
	}
	a=K;
	while(a>0)
	{
		a=a/10;
		count++;
	}
	c=N;
	while(c>0)
	{
		c=c/10;
		count2++;
	}
	while(count2 > count+1)
	{
		N = N / 10;
		count2--;
	}
	while(1)
	{
		b = N;
		N = N - K;
		if(N < 0)
		{
			N = N * -1;
		}
		if(b < N)
		{
			N = b;
			break;
		}

	}

	printf("%ld\n",N);
	return 0;
}