#include <bits/stdc++.h>
using namespace std;
int h;
long long n;
long long dfs(int d, long long n, int lr) {
  if (d == h) return 0;
  if (!lr && n > (1LL << (h - d - 1)))
    return (1LL << (h - d)) + dfs(d + 1, n - (1LL << (h - d - 1)), 0);
  if (lr && n <= (1LL << (h - d - 1)))
    return (1LL << (h - d)) + dfs(d + 1, n, 1);
  if (!lr && n <= (1LL << (h - d - 1))) return dfs(d + 1, n, 1) + 1;
  if (lr && n > (1LL << (h - d - 1)))
    return dfs(d + 1, n - (1LL << (h - d - 1)), 0) + 1;
}
int main() {
  scanf("%d%I64d", &h, &n);
  printf("%I64d\n", dfs(0, n, 0));
  return 0;
}
