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