#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

#define ll long long
#define fr(n) for(i=0;i<n;i++)
#define frr(n) for(i=n;i>=0;i--)

int main(){
        ll n,k;
        cin>>n>>k;
        if(n>k&&n%k==0||k>n&&k%n==0){
                cout<<k<<endl;
        }
        else{
                ll a,b;
                a=abs(n-k);
                b=abs(a-k);
                if(a<b) cout<<a<<endl;
                else cout<<b<<endl;

        }
        return 0;

}

