#include #include #include #include #include #include using namespace std; typedef long long int lint; int main() { int N, K; cin >> N >> K; if (K == 0 || K > N) { cout << 0 << endl; } else if (N % 2 == 1 && K == N / 2 + 1) { cout << N - 1 << endl; } else { cout << N - 2 << endl; } }