#include using namespace std; //#include //using namespace atcoder; using ll = long long int; using ull = unsigned long long int; using ld = long double; constexpr ll MAX = 2000000000000000000; constexpr ld PI = 3.14159265358979; constexpr ll MOD = 998244353;//2024948111; ld dotorad(ld K){return PI * K / 180.0;} ld radtodo(ld K){return K * 180.0 / PI;} mt19937 mt; void randinit(){srand((unsigned)time(NULL));mt = mt19937(rand());} int main(){ ll N,M; cin >> N >> M; if(N < 62 && M >= (1 << (N - 1))){ cout << (1 << (N)) - 1 << endl; return 0; } ll ans = 0; vector A; while(M != 1){ A.emplace_back(M); if(M & 1) M = (M + 1) / 2; else M /= 2; } A.emplace_back(1); reverse(A.begin(),A.end()); ll a = (ll)A.size(); for(ll i = 0;i < min(a,N);i++) ans += A[i]; if(N <= a) cout << ans << endl; else cout << ans + (N - a) << endl; }