#include <bits/stdc++.h>
using namespace std;
int in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
long long int solve(long long int H, long long int N, long long int R) {
  if (H <= 0) return 0;
  long long int res = 0;
  res++;
  if (!R) {
    if (N > (1LL << (H - 1))) {
      res += (1LL << H) - 1;
      res += solve(H - 1, N - (1LL << (H - 1)), 0);
    } else {
      res += solve(H - 1, N, 1);
    }
  } else {
    if (N > (1LL << (H - 1))) {
      res += solve(H - 1, N - (1LL << (H - 1)), 0);
    } else {
      res += (1LL << H) - 1;
      res += solve(H - 1, N, 1);
    }
  }
  return res;
}
int main() {
  long long int H, N, res = 0;
  cin >> H >> N;
  res += solve(H, N, 0);
  cout << res << endl;
  return 0;
}
