#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l, r, b, ans = 0, h, n;
  cin >> h >> n;
  l = 1, r = (1LL << h), b = 0;
  for (int i = h; i >= 0; i--) {
    long long mid = (l + r) / 2;
    if ((b % 2 == 0 && mid < n) || (b % 2 == 1 && n <= mid)) {
      ans += (1LL << i) - 1;
      b++;
    }
    if (b % 2 == 1) {
      l = mid + 1;
    } else {
      r = mid;
    }
    ans++;
    if (l == r) break;
    b++;
  }
  cout << ans;
  return 0;
}
