#include <bits/stdc++.h>
using namespace std;
vector<long long> t;
long long n, h, q[51];
int main() {
  q[0] = 1;
  for (int i = 0; i < 50; i++) {
    q[i + 1] = 2 * q[i];
  }
  cin >> h >> n;
  long long an = n;
  for (int i = 0; i < h; i++) {
    t.push_back(an % 2);
    an = (an + (an % 2)) / 2;
  }
  long long pr = 0;
  long long ans = 1LL;
  for (int i = h - 1; i >= 0; i--) {
    if (t[i] != pr)
      ++ans;
    else {
      ans += q[h - (h - 1 - i)];
    }
    pr = t[i];
  }
  cout << (ans - 1) << '\n';
}
