#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = (int)5e6 + 7, mod = 1000000007, M = 1e9;
long long n, t, h, x = 1, c;
map<long long, bool> p;
bool w;
int main() {
  cin >> h >> n;
  n += pow(2, h) - 1;
  t = n;
  while (t > 1) p[t] = 1, t >>= 1;
  while (x != n) {
    if (p[x * 2 + w])
      x = x * 2 + w, c++, h--;
    else
      c += pow(2, h) - 1;
    w = !w;
  }
  cout << c;
  return 0;
}
