#include <bits/stdc++.h>
using namespace std;
long long BIT[200005];
void update(long long id, long long val) {
  for (long long i = id; i <= 200000; i += i & -i) BIT[i] += val;
}
long long query(long long id) {
  long long sum = 0;
  for (long long i = id; i > 0; i -= i & -i) sum += BIT[i];
  return sum;
}
long long ans = 0;
void f(long long h, long long n, bool dir) {
  if (h == 0) return;
  long long lim = ceil(pow(2ll, h - 1));
  if (n <= lim) {
    if (dir == 0) {
      ans++;
      f(h - 1, n, !dir);
      return;
    } else {
      ans += ceil(pow(2ll, h));
      f(h - 1, n, dir);
      return;
    }
  } else {
    if (dir == 0) {
      ans += ceil(pow(2ll, h));
      f(h - 1, n - ceil(pow(2ll, h - 1)), dir);
      return;
    } else {
      ans++;
      f(h - 1, n - ceil(pow(2ll, h - 1)), !dir);
      return;
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  long long h, n;
  cin >> h >> n;
  f(h, n, 0);
  cout << ans << endl;
  return 0;
}
