#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<long long> stk;
  long long h, n, tot, flag, tmp, hh;
  while (cin >> h >> n) {
    n--;
    hh = h;
    while (h) {
      stk.push(n);
      n /= 2;
      h--;
    }
    tot = 0;
    tmp = 1;
    while (!stk.empty()) {
      long long q = stk.top();
      stk.pop();
      flag = ((tmp & 1) == (q & 1));
      if (flag)
        tot += (1LL << (stk.size() + 1));
      else
        tot += 1;
      tmp = q;
    }
    cout << tot << endl;
  }
  return 0;
}
