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