#include <bits/stdc++.h>
using namespace std;
unsigned long long int n, k, t[55];
void pre() {
  t[0] = 1;
  for (int i = 1; i <= 50; ++i) t[i] = t[i - 1] * 2;
}
unsigned long long int bs(unsigned long long int h, unsigned long long int x,
                          bool mark) {
  unsigned long long int e = t[h - 1];
  if (h == 1) {
    if (!mark) {
      if (x == 1)
        return 1;
      else
        return 2;
    } else {
      if (x == 1)
        return 2;
      else
        return 1;
    }
  }
  if (!mark) {
    if (x <= e) {
      return (bs(h - 1, x, 1) + 1);
    } else {
      x = x % e;
      if (x == 0) x = e;
      return ((bs(h - 1, x, 0)) + (2 * e));
    }
  } else {
    if (x > e) {
      x = x % e;
      if (x == 0) x = e;
      return (bs(h - 1, x, 0) + 1);
    } else {
      return ((bs(h - 1, x, 1)) + (2 * e));
    }
  }
}
int main() {
  pre();
  cin >> n >> k;
  unsigned long long int e = bs(n, k, 0);
  cout << e << endl;
}
