#include <bits/stdc++.h>
using namespace std;
long long binary(long long level, long long l, long long r, long long flag,
                 long long value) {
  if (l == r) return 0;
  long long mid = (l + r) / 2;
  if (value <= mid) {
    if (flag == 0)
      return binary(level - 1, l, mid, 1, value) + 1;
    else
      return binary(level - 1, l, mid, 1, value) + pow(2, level);
  }
  if (value > mid) {
    if (flag == 1)
      return binary(level - 1, mid + 1, r, 0, value) + 1;
    else
      return binary(level - 1, mid + 1, r, 0, value) + pow(2, level);
  }
}
int main() {
  long long h, n;
  cin >> h >> n;
  cout << binary(h, 1, pow(2, h), 0, n) << endl;
  return 0;
}
