#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n, k; cin >> n >> k; bool ne = (n%2 == 0); bool ke = (k%2 == 0); int ans; if(ne == true){ n /= 2; ans = min(n, k+1); }else{ if(ke == true){ ans = min(n, k+1); }else{ k = (k+1)/2; ans = min(n, 2*k); } } cout << ans << endl; return 0; }