#include<stdio.h>
#include<math.h>
int main()
{
   long long int a,b,i;
   scanf("%lld %lld",&a,&b);
   if(a < b)
   {
      printf("%lld\n",a);
   }
   else
   {
      i=a;
      while(i >= 0)
      {
         i = i-b;
      }
      if(i < 0)
      {
         printf("%lld\n",-(i));
      }
      else
      {
         printf("%lld\n",i);
      }
   }
   return 0;
}
