#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
  int n,k,i,ans,p,f;
  scanf("%d %d",&n,&k);
  p=n;
  while(1){
    f=abs(p-k);
    if(p<=f)printf("%d",p);break;
    p=f;
  }
  return 0;
}
