#include <bits/stdc++.h>
long long tar;
long long dfs(long long h, long long n, bool turn) {
  if (h == 0 && tar == n) return 0;
  if ((1LL << (h - 1)) < tar && turn == true) {
    tar -= 1LL << (h - 1);
    return (1LL << (h + 1)) / 2 + dfs(h - 1, 1, true);
  }
  if ((1LL << (h - 1)) >= tar && turn == false) {
    return (1LL << (h + 1)) / 2 + dfs(h - 1, 1, false);
  }
  if (turn == true)
    return 1 + dfs(h - 1, 1, false);
  else {
    tar -= 1LL << (h - 1);
    return 1 + dfs(h - 1, 1, true);
  }
}
int main(void) {
  long long h, n;
  scanf("%lld %lld", &h, &tar);
  bool turn = true;
  printf("%lld\n", dfs(h, 1LL, turn));
  return 0;
}
