#include <bits/stdc++.h>
using namespace std;
long long nodes[60];
long long height, n;
long long go(int h, long long second, long long e, bool left) {
  if (h == 0) {
    return 0;
  }
  if (left) {
    if (n >= second && n <= (second + e) / 2)
      return go(h - 1, second, (second + e) / 2, 0) + 1;
    else
      return nodes[h - 1] + go(h - 1, (second + e) / 2 + 1, e, 1) + 1;
  } else {
    if (n >= (second + e) / 2 + 1 && n <= e)
      return go(h - 1, (second + e) / 2 + 1, e, 1) + 1;
    else
      return nodes[h - 1] + go(h - 1, second, (second + e) / 2, 0) + 1;
  }
}
int main() {
  for (int i = 0; i <= 51; i++) {
    for (int j = 0; j <= i; j++) nodes[i] += pow(2, j);
  }
  cin >> height >> n;
  cout << go(height, 1, pow(2, height), 1);
}
