#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int h, n, max, prev, alt, hcur, ct, cur;
  cin >> h >> n;
  max = pow(2, h);
  prev = pow(2, h) - 1;
  cur = 1;
  vector<long long int> s, a;
  s.push_back(1);
  a.push_back(1);
  hcur = 0;
  alt = 0;
  ct = 0;
  while (h >= hcur) {
    if (h == hcur && (cur - prev) == n) {
      break;
    }
    long long int tempn = n + prev;
    while (tempn > cur) {
      tempn = tempn / 2;
    }
    if (tempn == cur && hcur < h) {
      ct++;
      if (alt == 0) {
        s.push_back(2 * cur + 1);
        cur = 2 * cur;
        a.push_back(0);
        hcur++;
        alt = 1;
      } else {
        s.push_back(2 * cur);
        cur = 2 * cur + 1;
        a.push_back(1);
        hcur++;
        alt = 0;
      }
    } else {
      cur = s[s.size() - 1];
      alt = a[a.size() - 1];
      s.pop_back();
      a.pop_back();
      ct += (pow(2, (h - hcur + 1)) - 1);
    }
  }
  cout << ct;
  return 0;
}
