#include "bits/stdc++.h" using namespace std; #define Would #define you const int INF = 999999999; const int MOD = 1e9 + 7; const double pi = 3.141592653589793238; int main() { long long a, b, ans; cin >> a >> b; if (b == 0 || b > a) { ans = 0; } else if (a % 2 == 0) { ans = a - 2; } else { if (2 * b == a + 1) { ans = a - 1; } else { ans = a - 2; } } cout << ans << endl; }