#include <bits/stdc++.h>
using namespace std;
long long makeLong(int power) {
  long long a = 1;
  for (int i = 0; i < power; i++) {
    a <<= 1;
  }
  return a;
}
long long solve(int h, long long n, int mv) {
  if (h == 0) return 0;
  if (mv == 0 && n <= makeLong(h - 1)) {
    return 1 + solve(h - 1, n, 1 - mv);
  } else if (mv == 1 && n > makeLong(h - 1)) {
    return 1 + solve(h - 1, n - makeLong(h - 1), 1 - mv);
  } else if (mv == 0 && n > makeLong(h - 1)) {
    return makeLong(h) + solve(h - 1, n - makeLong(h - 1), mv);
  } else {
    return makeLong(h) + solve(h - 1, n, mv);
  }
}
int main() {
  int h;
  long long n;
  cin >> h >> n;
  cout << solve(h, n, 0) << endl;
}
