#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int h, position, flag = 0, turn = 0;
  long long int count = 0, i, level;
  cin >> h >> position;
  for (i = 0, level = h, turn = 0; level > -1; i++, level--) {
    if (position > pow(2, level) / 2) {
      if (turn == 0)
        count += pow(2, level), position -= pow(2, level) / 2;
      else
        count++, turn ^= 1, position -= pow(2, level) / 2;
    } else {
      if (turn == 0)
        count++, turn ^= 1;
      else
        count += pow(2, level);
    }
  }
  cout << count - 1 << '\n';
  return 0;
}
