#include <bits/stdc++.h>
using namespace std;
const int MN = 100 * 100 * 100 * 10;
long long n, h, ans;
bool f(long long height, long long num) {
  if (height == 1) return 0;
  long long tmp = (long long)(num + 1) % 2;
  return (1 + tmp) % 2;
}
int main() {
  cin >> h >> n;
  h++;
  long long s = 0;
  for (int i = 0; i < h; i++) {
    s++;
    if (i == h - 1) break;
    long long tmp1 = (long long)((n + 1) / 2), tmp2 = (long long)(h - i) % 2;
    tmp1 = (long long)tmp1 % 2;
    long long ttt = (long long)(n + 1) / 2;
    if (f(h - i - 1, ttt) != (n + 1) % 2) {
      long long chem = (long long)1 << (i + 2);
      chem = (long long)chem / 2;
      chem--;
      s += chem;
    }
    n = (long long)(n + 1) / 2;
  }
  cout << s - 1;
  return 0;
}
