#include <bits/stdc++.h>
using namespace std;
int h;
long long dfs(int deep, long long node) {
  if (node == 1) return 1LL << h;
  long long xx = (2LL << deep) - 1;
  if (deep != h - 1) xx = -xx;
  if (node <= (1LL << deep))
    return dfs(deep - 1, node);
  else
    return dfs(deep - 1, (2LL << deep) - node + 1) + xx;
}
int main() {
  long long n;
  cin >> h >> n;
  cout << dfs(h - 1, n) - 1 << endl;
  return 0;
}
