#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  unsigned long long k, res = 0;
  cin >> n >> k;
  unsigned long long *arr = new unsigned long long[n + 1];
  arr[0] = 1;
  for (int i = 1; i <= n; i++) arr[i] = arr[i - 1] * 2;
  bool left = true;
  while (n > 1) {
    if (k > arr[n - 1]) {
      if (left) {
        res += arr[n];
      } else {
        res++;
        left = true;
      }
      k -= arr[n - 1];
    } else {
      if (left) {
        res++;
      } else {
        res += arr[n];
      }
      left = false;
    }
    n--;
  }
  if (k == 1 && left)
    res += 2;
  else if (k == 2 && left)
    res += 3;
  else if (k == 1)
    res += 3;
  else
    res += 2;
  cout << res - 1;
  return 0;
}
