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