#include using namespace std; int main(){ long int n, k; cin >> n >> k; if (k == 0 || k > n || (n==1 && k==1) || (n==2 && k==2)) cout << 0 << endl; else{ if (k != n-k+1) cout << n - 2 << endl; else cout << n-1 << endl; } }