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

int main(void){
  int n, k, i, f = 0, s;
  
  s = n;
  do{
    n = abs(n -k);
    if(n < s){
      s = n;
    }else if(n == s){
      f = 1;
    }
  }while(f == 0);
  
  printf("%d", s);
  
  return 0;
}