#include using namespace std; int main( int argc, char *argv[] ) { int N; int K; int iAns; ios::sync_with_stdio( false ); cin.tie( 0 ); cin >> N; cin >> K; if( K <= 0 || N <= 0 || K > N ) iAns = 0; else if( K * 2 - 1 == N ) iAns = N - 1; else iAns = N - 2; cout << iAns << endl; return 0; }