#include <bits/stdc++.h>
using namespace std;
int h;
long long n;
void DEI(long long node, int depth, char direction, long long st,
         long long dr) {
  if (depth == h) {
    cout << node;
    return;
  }
  long long mid = (st + dr) / 2;
  if (n <= mid) {
    if (direction == 'l')
      DEI(node + 1, depth + 1, 'r', st, mid);
    else
      DEI(node + (1LL << (h - depth)), depth + 1, 'r', st, mid);
  } else {
    if (direction == 'r')
      DEI(node + 1, depth + 1, 'l', mid + 1, dr);
    else
      DEI(node + (1LL << (h - depth)), depth + 1, 'l', mid + 1, dr);
  }
}
int main() {
  cin >> h >> n;
  DEI(0, 0, 'l', 1, 1LL << h);
  return 0;
}
