#include <bits/stdc++.h>
using namespace std;
long long solve(long long h, long long n, bool isLeft) {
  if (h == 0) return 0;
  long long nn = ((long long)1 << (h - 1));
  if (isLeft) {
    if (n <= nn)
      return (long long)1 + solve(h - 1, n, !isLeft);
    else {
      return ((long long)1 << h) + solve(h - 1, n - nn, isLeft);
    }
  } else {
    if (n <= nn) {
      return ((long long)1 << h) + solve(h - 1, n, isLeft);
    } else {
      return (long long)1 + solve(h - 1, n - nn, !isLeft);
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  long long h, n;
  cin >> h >> n;
  cout << solve(h, n, true) << endl;
  return 0;
}
