#include <bits/stdc++.h>
using namespace std;
int main() {
  int h;
  long long n;
  long long answer = 0;
  cin >> h >> n;
  int a[h];
  n--;
  for (int i = 0; i < h; i++) {
    a[i] = n / pow(2, (h - 1 - i));
    if (a[i] == 1) n -= pow(2, (h - 1 - i));
  }
  int cur = 0, i = 0;
  while (i < h) {
    if (cur == a[i]) {
      answer += 1;
      cur = 1 - cur;
      i++;
    } else {
      answer += pow(2, h - i);
      i++;
    }
  }
  cout << answer << endl;
  return 0;
}
