#include #include #include #include #include using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n,k; cin >> n >> k; if(k > n || k == 0) cout << 0 << endl; else if(n % 2 == 1 && k == (n+1)/2) cout << n - 1 << endl; else cout << n - 2 << endl; }