#include <bits/stdc++.h>
using namespace std;
long long dfs(int h, long long n, long long mid, bool d) {
  if (h == 0) {
    return 0;
  }
  if (n <= mid / 2 && d == false) {
    return dfs((h - 1), n, mid / 2, !d) + 1;
  } else if (n <= mid / 2) {
    return dfs((h - 1), n, mid / 2, d) + mid;
  } else if (d == false) {
    return dfs((h - 1), n - mid / 2, mid / 2, d) + mid;
  } else
    return dfs(h - 1, n - mid / 2, mid / 2, !d) + 1;
}
int main() {
  int h;
  long long n;
  long long ch;
  cin >> h >> n;
  ch = pow(2, h);
  cout << dfs(h, n, ch, false);
}
