#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
const unsigned long long ULINF = ULLONG_MAX;
const double EPS = 0.000001;
unsigned long long step(int x) {
  unsigned long long ans = 1;
  for (int i = 0; i < x; i++) ans = ans << 1;
  return ans;
}
int main() {
  unsigned long long h, n, n2;
  cin >> h >> n;
  vector<long long> r;
  n = step(h) + n - 1;
  n2 = n;
  r.push_back(n);
  while (n != 1) {
    n /= 2;
    r.push_back(n);
  }
  reverse(r.begin(), r.end());
  int i = 1;
  unsigned long long ans = 1;
  while (i < r.size()) {
    if (r[i] % 2 == 0) {
      if (r[i - 1] % 2 != 0)
        ans++;
      else
        ans += step(h - i + 1);
      i++;
    } else {
      if (r[i - 1] % 2 == 0)
        ans++;
      else
        ans += step(h - i + 1);
      i++;
    }
  }
  cout << ans - 1 << "\n";
  return 0;
}
