#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &n) {
  T x = 0, tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
  if (c == EOF) return false;
  if (c == '-') c = getchar(), tmp = -1;
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  n = x * tmp;
  return true;
}
template <class T>
inline void write(T n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  int len = 0, data[20];
  while (n) {
    data[len++] = n % 10;
    n /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
}
long long pow2[60];
int main() {
  pow2[0] = 1;
  for (int i = 1; i <= 50; i++) {
    pow2[i] = pow2[i - 1] * 2;
  }
  long long h, n;
  while (read(h) && read(n)) {
    long long ans = 0;
    for (int i = h - 1; i >= 0; i--) {
      if (n <= pow2[i]) {
        ans += 1;
        n = pow2[i] + 1 - n;
      } else {
        ans += pow2[i + 1];
        n -= pow2[i];
      }
    }
    write(ans);
    putchar('\n');
  }
}
