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