#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, n;
  while (cin >> h >> n) {
    vector<long long> V;
    int temp = h;
    while (temp--) {
      V.push_back(n);
      if (n % 2 != 0) {
        n++;
      }
      n /= 2;
    }
    int len = V.size();
    int i;
    long long ans = 1;
    for (i = 0; i < h; i++) ans *= 2;
    int now = 1;
    long long cot = 1;
    for (i = len - 1; i >= 0; i--) {
      if (V[i] % 2 == now) {
        cot++;
        now = 1 - now;
      } else
        cot += ans;
      ans /= 2;
    }
    cout << cot - 1 << endl;
  }
  return 0;
}
