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