#include <bits/stdc++.h>
using namespace std;
long long two[51];
void init() {
  two[0] = 1;
  for (int i = 1; i < 51; i++) two[i] = two[i - 1] * 2;
}
long long dfs(long long h, long long n, int dir) {
  if (h == 0) return 0;
  long long vis = 1;
  int req = (n > (1LL << (h - 1)));
  if (req != dir) vis += two[h] - 1;
  if (n > (1LL << (h - 1))) n -= (1LL << (h - 1));
  vis += dfs(h - 1, n, req ^ 1);
  return vis;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  init();
  long long h, n;
  cin >> h >> n;
  cout << dfs(h, n, 0) << "\n";
  return 0;
}
