#include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) int main() { int L, K; cin >>L>>K; int a = L-L/(K<<1)*K; if(a<=0) cout << 0 << endl; else cout << a << endl; return 0; }