#include<stdio.h>

int main(){
  long int n,k;
  char buff[1000];#include<stdio.h>

int main(){
  long int n,k;
  char buff[1000];

  if(fgets(buff,sizeof(buff),stdin)!=NULL){
    sscanf(buff,"%ld%ld",&n,&k);
  }

  n = n % k;
  if(k-n >= n){
    printf("%ld",n);
    return 0;
  }else{
    printf("%ld",k-n);
    return 0;
  }
}


  if(fgets(buff,sizeof(buff),stdin)!=NULL){
    sscanf(buff,"%ld%ld",&n,&k);
  }

  n = n % k;
  printf("%ld\n",n);
  if(k-n >= n){
    printf("%ld",n);
    return 0;
  }else{
    printf("%ld",k-n);
    return 0;
  }
}
