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