#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) using ll = long long; using pii = pair; using pll = pair; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; int main() { int N, K; cin >> N >> K; if(K % 2 == 0) { if(N % 2 == 0) { cout << min(K + 1, N / 2) << endl; } else { cout << min(K + 1, N - 1) << endl; } } else { if(N % 2 == 0) { cout << min(N / 2, (K / 2 + 1) * 2) << endl; } else { cout << min(N - 1, (K / 2 + 1) * 2) << endl; } } return 0; }