#include <bits/stdc++.h>
using namespace std;
long long processNode(long long nodeStart, long long nodeFinish,
                      bool needTurnLeft, long long stepID, long long currH,
                      long long targetPos) {
  if (currH == 1) {
    return stepID - 1;
  }
  long long center = nodeStart + (nodeFinish - nodeStart) / 2;
  bool targetIsLeft = targetPos < center;
  long long incrementSize = 1;
  long long nextNodeFrom = nodeStart;
  long long nextNodeTo = nodeFinish;
  if (targetIsLeft) {
    nextNodeTo = center;
  }
  if (!targetIsLeft) {
    nextNodeFrom = center;
  }
  if (needTurnLeft != targetIsLeft) {
    incrementSize = pow(2, currH - 1);
    needTurnLeft = targetIsLeft;
  }
  return processNode(nextNodeFrom, nextNodeTo, !needTurnLeft,
                     stepID + incrementSize, currH - 1, targetPos);
}
int main() {
  long long h, n;
  cin >> h;
  cin >> n;
  --n;
  long long res = processNode(0, pow(2, h), true, 1, h + 1, n);
  cout << res << "\n";
  return 0;
}
