#include <bits/stdc++.h>
using namespace std;
const long long linf = 5e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
int h;
long long n, ans;
long long tot(int ref) {
  long long sum = 0;
  for (int i = 0; i <= ref; i++) {
    sum += (1LL << i);
  }
  return sum;
}
void solve(long long h, long long n, bool dir) {
  if (h == 0) {
    cout << ans << endl;
    exit(0);
  }
  if (dir == true) {
    if (n > 1LL << (h - 1)) {
      ans += tot(h - 1) + 1;
      solve(h - 1, n - (1LL << (h - 1)), dir);
    } else {
      ans++;
      solve(h - 1, n, !dir);
    }
  } else if (dir == false) {
    if (n <= 1LL << (h - 1)) {
      ans += tot(h - 1) + 1;
      solve(h - 1, n, dir);
    } else {
      ans++;
      solve(h - 1, n - (1LL << (h - 1)), !dir);
    }
  }
}
int main() {
  cin >> h >> n;
  solve(h, n, true);
  return 0;
}
