#include<stdio.h>
#include<stdlib.h>

int main(void){

  int N,K;
  int N_new = 0;
  
  scanf("%d %d",&N,&K);
  
  while(N_new <= N){
    N_new = N-K;
	N_new = abs(N_new);
  }

    printf("%d",N_new);
      
  return 0;
  
  }