#include <bits/stdc++.h>   using namespace std;   map<long long, map<long long, long long, greater<long long>>> comp;   map<long long, long long, greater<long long>> Add(long long x) {     if (x == 0) return {};     if (comp.count(x)) return comp[x];     long long choose = (x - 1) / 2;     long long diff = min(choose + 1, x - choose);     map<long long, long long, greater<long long>> ret = {{diff, 1}};     for (long long xp : {choose, x - choose - 1})       for (auto p : Add(xp)) ret[p.first] += p.second;     return comp[x] = ret;   }   long long Solve(long long x, long long seek, long long& cnt) {     long long choose = (x - 1) / 2;     long long diff = min(choose + 1, x - choose);     if (diff == seek) {       return choose + cnt;     }     long long ret = 0;     for (long long xp : {choose, x - choose - 1}) {       long long now = Add(xp)[seek];       if (now > cnt) {         return ret + Solve(xp, seek, cnt);       }       cnt -= now;       ret += choose + 1;     }     assert(false);   }   int32_t main() {     long long n, k;     cin >> n >> k;     if (k == 1) {       cout << 1 << endl;       return 0;     }     if (k == 2) {       cout << n << endl;       return 0;     }     n -= 2;     k -= 3;     for (auto p : Add(n)) {       if (p.second > k) {         cout << 2 + Solve(n, p.first, k) << endl;         return 0;       }       k -= p.second;     }     assert(false);     return 0;   }   