#include <bits/stdc++.h>
using namespace std;
int h;
long long n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> n;
  vector<char> v;
  for (long long x = n + (1LL << h) - 1LL; x > 1; x /= 2) {
    v.push_back(x % 2 ? 'R' : 'L');
  }
  string z(v.rbegin(), v.rend());
  char x = 'L';
  unsigned long long ans = 1;
  unsigned long long sz = (1ULL << h) + (1ULL << h) - 1;
  sz /= 2;
  for (size_t i = 0; i < z.length(); ++i, sz /= 2) {
    if (x != z[i]) {
      ans += sz;
      x = x == 'L' ? 'R' : 'L';
    }
    ans += 1;
    x = x == 'L' ? 'R' : 'L';
  }
  ans -= 1;
  cout << ans << '\n';
}
