#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long h, cur = 1;
  long long pos;
  while (cin >> h >> pos) {
    bool des = 1;
    cur = 1;
    while (h) {
      if (des == 1) {
        if (pos > 1LL << (h - 1)) {
          des = 1;
          cur += 1LL << h;
          pos -= 1LL << (h - 1);
        } else {
          des = 0;
          cur++;
        }
        h--;
      } else {
        if (pos <= 1LL << (h - 1)) {
          des = 0;
          cur += 1LL << h;
        } else {
          des = 1;
          cur++;
          pos -= 1LL << (h - 1);
        }
        h--;
      }
    }
    cout << cur - 1 << endl;
  }
}
