#include <bits/stdc++.h>
using namespace std;
int main() {
  int h;
  long long n;
  while (cin >> h >> n) {
    n -= 1;
    long long res = 0LL;
    for (int i = h - 1; i >= 0; --i) {
      int level = i + 1;
      if (n & (1LL << i)) {
        if (res & 1) {
          res += 1;
        } else {
          res += (1LL << level);
        }
      } else {
        if (res & 1) {
          res += (1LL << level);
        } else {
          res += 1;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
