#include <bits/stdc++.h>
using namespace std;
long long h, n;
long long ret = 0LL;
int a[60];
long long two(int x) {
  if (x == 0) return 1LL;
  long long half = two(x / 2);
  half *= half;
  return x % 2 ? half * 2 : half;
}
void solve() {
  int c = 0;
  --n;
  while (n) {
    a[c++] = n % 2;
    n >>= 1;
  }
  for (int i = c; i < h; ++i) a[i] = 0;
  int e = 0;
  for (int i = h - 1; i >= 0; --i) {
    if (a[i] != e) {
      ret += two(i + 1);
    }
    if (a[i] == e) {
      ret += 1;
      e = !e;
    }
  }
  cout << ret << endl;
}
int main() {
  cin >> h >> n;
  solve();
  return 0;
}
