#include using namespace std; int main(){ int N, K; cin >> N >> K; if (K == 0){ cout << 0 << endl; } else if (K > N){ cout << 0 << endl; } else if (N == K * 2 - 1){ cout << N - 1 << endl; } else { cout << N - 2 << endl; } }