#include <stdio.h>
#include <stdlib.h>
int main (){
  int N=0;
  int K=0;
  int i=0;
  int j=0;
  scanf("%d %d", &N, &K);
  while(){
  	i = N - K;
  	j = abs(i);
  	N = j;
  }
  printf("%d", N);
  return 0;
}