#include <bits/stdc++.h>
using namespace std;
long long n, h, ok;
long long cal(long long d, long long pos, int dir) {
  long long rt = 0;
  if (ok) return 0;
  if (!d) {
    ok = 1;
    return 0;
  }
  if (!dir) {
    if (pos > (1LL << (d - 1)))
      rt = (1LL << d) + cal(d - 1, pos - (1LL << (d - 1)), 0);
    else
      rt = 1LL + cal(d - 1, pos, 1);
  } else {
    if (pos > (1LL << (d - 1)))
      rt = 1LL + cal(d - 1, pos - (1LL << (d - 1)), 0);
    else
      rt = (1LL << d) + cal(d - 1, pos, 1);
  }
  return rt;
}
int main() {
  while (cin >> h >> n) ok = 0, cout << cal(h, n, 0) << endl;
}
