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