#include <bits/stdc++.h>
using namespace std;
const int LEFT = 0;
const int RIGHT = 1;
long long rec(int h, long long n, int p = LEFT) {
  if (h == 0) return 0;
  if ((n >> (h - 1)) & 1) {
    if (p == LEFT)
      return (1LL << h) + rec(h - 1, n, LEFT);
    else
      return 1 + rec(h - 1, n, LEFT);
  } else {
    if (p == LEFT)
      return 1 + rec(h - 1, n, RIGHT);
    else
      return (1LL << h) + rec(h - 1, n, RIGHT);
  }
}
int main() {
  int h;
  long long n;
  while (cin >> h >> n) {
    cout << rec(h, n - 1) << endl;
  }
  return 0;
}
