#include <bits/stdc++.h>
using namespace std;
long long ans = 1, n, h;
long long f(long long h, long long st, long long ed, int lr) {
  if (ed == st) {
    return ans;
  }
  h--;
  long long ed1 = ed, st1 = st, ed2 = ed, st2 = st;
  if (lr == 0) {
    ed1 = (st + ed - 1) / 2;
    st2 = (ed + st + 1) / 2;
  }
  if (lr == 1) {
    st1 = (ed + st + 1) / 2;
    ed2 = (st + ed - 1) / 2;
  }
  lr = -1 * lr + 1;
  if (st1 <= n && n <= ed1) {
    ans++;
    return f(h, st1, ed1, lr);
  } else
    ans += (1ll << (h + 1));
  return f(h, st2, ed2, -1 * lr + 1);
}
int main() {
  int i, j;
  cin >> h >> n;
  long long v = f(h, 1, (1ll << h), 0);
  cout << v - 1 << endl;
  return 0;
}
