#include <stdio.h>
 
int main(void)
{
 int n,k,ans,n1;
  
  scanf("%d %d", &n, &k);
  n1 = n;
  
  while(1){
    ans = n - k;
    if(ans < 0)
      ans = ans * -1;
    
    if(n1 <= ans)
      break;
    else
      n1 = ans;
  }
  printf("%d", ans);
  
  return 0;  
}