#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; if (K == 0 || K > N) { cout << 0 << '\n'; return 0; } if (K == N - K + 1) { cout << N - 1 << '\n'; } else { cout << N - 2 << '\n'; } return 0; }