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