#include <bits/stdc++.h>
using namespace std;
long long h, n, res;
int main() {
  cin >> h >> n;
  res = (long long)pow(2, h + 1) - 1;
  long long dir = 1, dir1 = 1;
  while (h--) {
    if (n <= (pow(2, h)))
      dir1 = -1LL;
    else
      n -= (pow(2, h)), dir1 = 1LL;
    if ((dir1 * dir) == -1) res -= (long long)(pow(2, h + 1)) - 1LL;
    dir = dir1;
  }
  cout << res - 1;
}
