#include <string.h>
#include <stdio.h>
int main(void){
  int n=-1;
  int k=-1;
  while(n<0 || n>1000000000000000000){scanf("%d",&n);}
  while(k<1 || k>1000000000000000000){scanf("%d",&k);}
  while(1){
    if(n>=k) n=n-k;
    else {printf("%d",n); goto OUT;}
  }
  OUT:
  return 0;
}
