#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; if(k > n || k == 0) cout << 0 << endl; else { if(n % 2 == 1) { if(k == (n + 1) / 2) cout << n - 1 << endl; else cout << n - 2 << endl; } else { cout << n - 2 << endl; } } return 0; }