#include #include #include using namespace std; typedef long long ll; int main(){ int n , k; cin >> n >> k; if(k >= n){ cout << n << endl; exit(0); } ll ans; if(n % 2 == 0){ if(k % 2 == 0)ans = min(k + 1 , n / 2); else ans = min(k , n / 2); }else{ if(k % 2 == 0)ans = min((k + 1) / 2 + (k + 1) / 2 + 1 , n); else ans = min((k + 1) / 2 + (k + 1) / 2 , n); } cout << ans << endl; return 0; }