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