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