#include <bits/stdc++.h>
using namespace std;
long long ct(int h, long long n, int st) {
  if (!h) return 0;
  int sub;
  long long inc, nn;
  sub = n > (1LL << (h - 1));
  inc = 1 + (sub != st) * ((1LL << h) - 1);
  nn = n - sub * (1LL << (h - 1));
  return ct(h - 1, nn, sub ^ 1) + inc;
}
int main() {
  int h;
  long long n;
  cin >> h >> n;
  cout << ct(h, n, 0);
  return 0;
}
