#include <bits/stdc++.h>
using namespace std;
int h;
long long n;
long long cal(int h, long long n, bool d) {
  if (h == 0) return 0;
  if (d == 0) {
    if (n <= (1LL << (h - 1)))
      return 1LL + cal(h - 1, n, 1);
    else
      return (1LL << h) + cal(h - 1, n - (1LL << (h - 1)), 0);
  } else {
    if (n > 1LL << (h - 1))
      return 1LL + cal(h - 1, n - (1LL << (h - 1)), 0);
    else
      return (1LL << h) + cal(h - 1, n, 1);
  }
}
int main() {
  cin >> h >> n;
  cout << cal(h, n, 0);
}
