#include <bits/stdc++.h>
using namespace std;
string nodepath(long long position, long long height) {
  string str = "";
  long long pos = position;
  long long ht = height;
  while (ht > 0) {
    long long val = (long long)pow(2, (ht - 1));
    if (pos <= val) {
      str += 'L';
      ht--;
    } else {
      str += 'R';
      pos = pos - val;
      ht--;
    }
  }
  return str;
}
int main() {
  string npath = "";
  long long H, N;
  cin >> H >> N;
  npath = nodepath(N, H);
  long long len = npath.length();
  char cmd = 'L';
  long long i = 0, hgt = len, count = 0;
  while (i < len) {
    if (cmd == npath[i]) {
      count++;
      hgt--;
      i++;
      if (cmd == 'L')
        cmd = 'R';
      else
        cmd = 'L';
    } else {
      count = count + ((long long)pow(2, hgt) - 1);
      if (cmd == 'L')
        cmd = 'R';
      else
        cmd = 'L';
    }
  }
  cout << count << endl;
  getchar();
  return 0;
}
