#include using namespace std; int main() { int N, K; cin >> N >> K; int x = 0; if (K<1 || K>N) x = N; else if (N == K * 2 - 1) x = 1; else x = 2; cout << (N - x) << endl; return 0; }