#include <bits/stdc++.h>
using namespace std;
class cf {
  int h;
  long long k;

 public:
  void read(void);
  void solve(void);
} cf;
void cf::read(void) {
  scanf("%d%I64d", &h, &k);
  --k;
  return;
}
void cf::solve(void) {
  long long l, r, t, ans;
  l = 0;
  t = r = (1LL << h);
  int op;
  op = 0;
  ans = 0;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if ((k >= m) ^ op)
      ans += t;
    else
      ++ans;
    t /= 2;
    if (k < m) {
      op = 1;
      r = m;
    } else {
      op = 0;
      l = m;
    }
  }
  printf("%I64d\n", ans);
  return;
}
int main(void) {
  cf.read();
  cf.solve();
  return 0;
}
