#include <bits/stdc++.h>
using namespace std;
long long out = 0;
vector<bool> put;
long long stdva[111];
int main() {
  long long n, a;
  cin >> n >> a;
  stdva[0] = 1;
  for (int i = 1; i < n + 10; i++) {
    stdva[i] = stdva[i - 1] * 2;
  }
  long long l = 1, r = (stdva[n]) + 1;
  while (l < r - 1) {
    long long m = (l + r) / 2;
    if (a >= m) {
      l = m;
      put.push_back(1);
    } else {
      r = m;
      put.push_back(0);
    }
  }
  bool poz = 0;
  for (long long i = 0; i < put.size(); i++) {
    if (poz != put[i]) {
      out += (stdva[(n - (i + 1) + 1)]) - 1;
    }
    poz = ((long long)put[i] + 1) % 2;
    out++;
  }
  cout << out;
  return 0;
}
