#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, n;
  cin >> h >> n;
  long long e = n + pow(2, h) - 1;
  long long h2 = h;
  long long ans = 0;
  while (e != 1) {
    long long p = e / 2;
    long long x = h - h2;
    if (e % 2 == p % 2) {
      ans = ans + 1 + pow(2, x + 1) - 1;
    } else {
      ans = ans + 1;
    }
    e = e / 2;
    h2--;
  }
  cout << ans;
  return 0;
}
