#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, n;
  cin >> h >> n;
  long long t = h;
  long long c = 1;
  long long k = (1ll << (h - 1));
  long long ans = 0;
  while (h > 0) {
    if ((2 * n - (2 * k + 1)) * c > 0) {
      ans += 2 * (1ll << (h - 1)) - 1;
      n = ((2 * k + 1) - (2 * n - (2 * k + 1))) / 2;
    }
    h = h - 1;
    k = k - c * ((1ll << (h)) / 2);
    c = c * -1;
  }
  cout << ans + t << endl;
}
