#include using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0; if (1 <= k && k <= n) { ans = (k == n - k + 1) ? n - 1 : n - 2; } cout << ans << endl; return 0; }