#include <bits/stdc++.h>
using namespace std;
unsigned long long flag[55];
int h;
unsigned long long ncount = (unsigned long long)1;
unsigned long long n;
void path(int level, unsigned long long leaf, int c) {
  if (level >= h) {
    ncount--;
    return;
  }
  unsigned long long l = pow(2, (h - level));
  l = l / (unsigned long long)2;
  unsigned long long f = (leaf % l);
  if (f == 0) f = l;
  if (leaf <= l) {
    if (c == 0) {
      ncount++;
      path(level + 1, f, ((c + 1) % 2));
    } else {
      ncount += flag[h - level] / (unsigned long long)2;
      ncount++;
      path(level + 1, f, c);
    }
  } else {
    if (c == 1) {
      ncount++;
      path(level + 1, f, ((c + 1) % 2));
    } else {
      ncount += flag[h - level] / (unsigned long long)2;
      ncount++;
      path(level + 1, f, c);
    }
  }
}
int main() {
  int c = 0, level = 0, i = 0;
  flag[0] = 0;
  flag[1] = (unsigned long long)2;
  for (i = 2; i <= 50; i++)
    flag[i] = (flag[i - 1] * (unsigned long long)2) + (unsigned long long)2;
  cin >> h >> n;
  unsigned long long leaf = n;
  if (h == 1 && n == 1) {
    cout << 1 << endl;
    return 0;
  }
  path(level, leaf, c);
  cout << ncount << endl;
  return 0;
}
