#include <bits/stdc++.h>
using namespace std;
vector<int> ord;
vector<long long> pot;
int main() {
  int h;
  long long n;
  scanf("%d %I64d", &h, &n);
  long long m = n;
  long long x = 1;
  for (int i = 0; i < h + 1; i++) {
    pot.push_back(x);
    x *= 2;
  }
  for (int i = 0; i < h; i++) {
    if (m % 2) {
      ord.push_back(0);
      m = (m + 1) / 2;
    } else {
      ord.push_back(1);
      m /= 2;
    }
  }
  reverse(ord.begin(), ord.end());
  int ha = h;
  int a = 0;
  long long r = 0;
  while (ha > 0) {
    if (a != ord[h - ha]) r += (pot[ha] - 1);
    r++;
    a = 1 - ord[h - ha];
    ha--;
  }
  printf("%I64d", r);
  return 0;
}
