#include using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vl; typedef long double ld; ll n, k; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; if(n%k == 0){ cout << "0\n"; } else{ n -= k; cout << 2*((n/2)%k) << "\n"; } return 0; }