#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int MOD1 = 1e9 + 35011;
const int MOD2 = 1e9 + 18169;
const int INF = (1 << 30);
const long long INFl = 1e18;
int h, init = 0, lvl = 0;
long long ans = 0, path[MAXN], n;
bool on_left = true;
int main() {
  scanf("%d%I64d", &h, &n);
  path[0] = (1LL << h) + n - 1;
  do {
    path[++init] = path[init - 1] >> 1;
  } while (path[init] != 1);
  long long nodes = (1LL << (h + 1)) - 1;
  while (init != 0) {
    long long lft = 2 * path[init--], rht = lft + 1;
    nodes >>= 1;
    if (path[init] == lft && on_left || path[init] == rht && !on_left) {
      ans++;
      on_left = !on_left;
    } else {
      ans += nodes + 1;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
