#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long n, h;
vector<int> f(long long n) {
  vector<int> v(h);
  long long i = 0;
  while (i < h) {
    v[i] = n % 2;
    n /= 2;
    i++;
  }
  reverse(v.begin(), v.end());
  return v;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> h >> n;
  long long p[51];
  p[0] = 1;
  for (int i = 1; i < 51; ++i) {
    p[i] = p[i - 1] * 2;
  }
  vector<int> v = f(n - 1);
  int curr = 0;
  long long ans = 0;
  for (int i = 0; i < h; ++i) {
    if (v[i] != curr) {
      ans += p[h - i];
    } else
      ans++;
    curr = 1 - v[i];
  }
  cout << ans << endl;
  return 0;
  ;
  return 0;
}
