#include using namespace std; int main(void) { long long a, b; cin >> a >> b; if (b >= 1 && b <= a) { if (a % 2 && (a + 1) / 2 == b) cout << max(0LL, a - 1) << endl; else cout << max(0LL, a - 2) << endl; } else cout << 0 << endl; return 0; }