#include <bits/stdc++.h>
using namespace std;
double rd() {
  double ret = 0.0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '.') c = getchar();
  while (c >= '0' && c <= '9') {
    ret = 10 * ret + c - 48;
    c = getchar();
  }
  if (c == '.') {
    c = getchar();
    long long ten = 10;
    while (c >= '0' && c <= '9') {
      ret += (double)(c - 48) / (ten * 1.0);
      ten *= 10;
      c = getchar();
    }
  }
  return ret;
}
int ri() {
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  int ret = 0, neg = 1;
  if (c == '-') {
    neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = 10 * ret + c - 48;
    c = getchar();
  }
  return ret * neg;
}
long long rl() {
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  long long ret = 0, neg = 1;
  if (c == '-') {
    neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = 10 * ret + c - 48;
    c = getchar();
  }
  return ret * neg;
}
string rs() {
  char c = getchar();
  while (c == '\n' || c == ' ') c = getchar();
  string ret = "";
  while (c != 10 && c != ' ') {
    ret += c;
    c = getchar();
  }
  return ret;
}
char rc() {
  char c = getchar();
  while (c == '\n' || c == ' ') c = getchar();
  return c;
}
long long exit_from(long long node, long long h, long long n) {}
long long left(long long n) { return 2 * n; }
long long right(long long n) { return 2 * n + 1; }
long long is_anc(long long n, vector<long long> &ances) {
  for (long long x : ances)
    if (x == n) return 1;
  return 0;
}
long long childs(long long n, long long h) {
  long long ch = 0, x = n, ret = 1, i;
  while (x != 1) {
    ch++;
    x /= 2;
  }
  return (1LL << h + 1 - ch) - 1;
  ;
}
long long correct(long long n, long long h) {
  long long x = 1, y = n, z[h], j = 0, i;
  for (i = 0; i < h; i++) z[i] = (y & (1LL << j++));
  for (i = h - 1; i >= 0; i--) {
    if (z[i] != 0)
      x = right(x);
    else
      x = left(x);
  }
  return x;
}
int main() {
  long long h = rl(), n = rl(), x, vis = 1, alt = 0, cn = 1;
  vector<long long> ances;
  n = correct(n - 1, h);
  x = n;
  while (x != 0) {
    x /= 2;
    ances.push_back(x);
  }
  ances.push_back(n);
  while (1) {
    if (cn == n) {
      cout << vis - 1;
      return 0;
    }
    if (alt) {
      if (is_anc(right(cn), ances)) {
        vis++;
        alt ^= 1;
        cn = right(cn);
        continue;
      } else {
        vis += childs(right(cn), h);
        alt ^= 1;
      }
    } else {
      if (is_anc(left(cn), ances)) {
        vis++;
        alt ^= 1;
        cn = left(cn);
        continue;
      } else {
        vis += childs(left(cn), h);
        alt ^= 1;
      }
    }
  }
  return 0;
}
