#include <bits/stdc++.h>
using namespace std;
vector<int> v;
long long po[55];
int main() {
  int i, j, k;
  int h, x;
  long long n;
  po[0] = 1ll;
  for (i = 1; i <= 50; i++) po[i] = 2 * po[i - 1];
  cin >> h >> n;
  n--;
  x = h;
  while (h--) {
    v.push_back(n % 2);
    n /= 2;
  }
  reverse(v.begin(), v.end());
  long long ans = 0;
  int next = 0;
  for (i = 0; i < x; i++) {
    if (v[i] != next)
      ans += po[x - i];
    else {
      ans++;
      next = 1 - next;
    }
  }
  cout << ans << endl;
  return 0;
}
