#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 55;
long long pot[MAX_N];
long long h, n;
void calc() {
  pot[0] = 1LL;
  for (int i = 1; i < MAX_N; i++) {
    pot[i] = 2LL * pot[i - 1];
  }
}
long long build(long long tl, long long tr, long long x, long long dir,
                long long actual) {
  if (tl == tr) return 0LL;
  long long tm = (tl + tr) / 2LL;
  if (x <= tm) {
    if (dir == 0)
      return 1LL + build(tl, tm, x, 1, actual + 1);
    else
      return pot[h - actual] + build(tl, tm, x, 1, actual + 1);
  } else {
    if (dir == 0)
      return pot[h - actual] + build(tm + 1, tr, x, 0, actual + 1);
    else
      return 1LL + build(tm + 1, tr, x, 0, actual + 1);
  }
}
int main() {
  ios::sync_with_stdio(0);
  calc();
  cin >> h >> n;
  cout << build(0LL, pot[h] - 1LL, n - 1LL, 0LL, 0LL) << endl;
  return 0;
}
