#include <bits/stdc++.h>
using namespace ::std;
int main() {
  long long n, height, ret = 0, d = 0, l, h, m, cheight;
  cin >> height >> n;
  l = 1;
  h = 1LL << height;
  cheight = height;
  while (l < h) {
    m = l + (h - l) / 2;
    if (n > m) {
      if (d == 0) {
        ret += (1LL << height) - 1;
        d ^= 1;
      }
      l = m + 1;
    } else if (n <= m) {
      if (d == 1) {
        ret += (1LL << height) - 1;
        d ^= 1;
      }
      h = m;
    }
    height--;
    d ^= 1;
  }
  cout << ret + cheight << endl;
  return 0;
}
