#include <bits/stdc++.h>
using namespace std;
bool is_anc(long long x, long long n) {
  while (n > x) n /= 2;
  return x == n;
}
int main() {
  int h;
  long long n;
  cin >> h >> n;
  n += (1LL << h) - 1;
  long long c = 1, v = 1;
  int d = 0, l = 0;
  while (c != n) {
    c = 2 * c + d;
    ++l;
    if (!is_anc(c, n)) {
      c ^= 1;
      v += 1LL << (h - l + 1);
    } else {
      d ^= 1;
      ++v;
    }
  }
  cout << v - 1 << '\n';
  return 0;
}
