#include <bits/stdc++.h>
using namespace std;
int h;
long long n;
long long dfs(int d, long long n, int lr) {
  if (d == h) return 0;
  long long tmp = 1ll << (h - d - 1);
  if (!lr && n <= tmp) return dfs(d + 1, n, !lr) + 1;
  if (!lr && n > tmp) return (tmp << 1) + dfs(d + 1, n - tmp, 0);
  if (lr && n <= tmp) return (tmp << 1) + dfs(d + 1, n, lr);
  if (lr && n > tmp) return dfs(d + 1, n - tmp, 0) + 1;
}
int main() {
  cin >> h >> n;
  cout << dfs(0, n, 0) << endl;
}
