#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, i, j, n, m, h, co = 1, nn;
  cin >> h >> n;
  long long int ans = 0, temp = 1, lh = h - 1, te;
  int pre = 0;
  nn = n + pow(2, h) - 1;
  string ch = "L";
  while (temp != nn) {
    te = pow(2, lh);
    if (ch == "L") {
      if (n <= te) {
        ans++;
        n %= te;
        if (n == 0) n = te;
        temp = temp * 2;
        ch = "R";
      } else {
        ans += pow(2, lh + 1);
        n %= te;
        if (n == 0) n = te;
        temp = temp * 2 + 1;
        ch = "L";
      }
      lh--;
    } else {
      if (n > te) {
        ans++;
        n %= te;
        if (n == 0) n = te;
        temp = temp * 2 + 1;
        ch = "L";
      } else {
        ans += pow(2, lh + 1);
        n %= te;
        if (n == 0) n = te;
        temp = temp * 2;
        ch = "R";
      }
      lh--;
    }
  }
  cout << ans;
  return 0;
}
