#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, h;
  cin >> h >> n;
  int dir = -1;
  long long i;
  long long counter = 0;
  long long pow2n[52];
  pow2n[0] = 1;
  for (i = 1; i <= h; i++) {
    pow2n[i] = pow2n[i - 1] * 2;
  }
  for (i = 0; i < h; i++) {
    if (dir == -1) {
      if (n <= pow2n[h - i - 1]) {
        counter++;
        dir *= (-1);
      } else {
        counter += pow2n[h - i];
        n -= pow2n[h - i - 1];
      }
    } else {
      if (n > pow2n[h - i - 1]) {
        counter++;
        dir *= (-1);
        n -= pow2n[h - i - 1];
      } else {
        counter += pow2n[h - i];
      }
    }
  }
  cout << counter << endl;
  return 0;
}
