#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
int main() {
  int h;
  long long n;
  while (cin >> h >> n) {
    long long ans = 1;
    bool curlr = false;
    for (int(i) = 0; (i) < (int)(h); ++(i)) {
      bool lr = (n - 1) >> (h - 1 - i) & 1;
      if (lr != curlr) {
        ans += (1LL << (h - i));
      } else {
        ans += 1;
      }
      curlr = !lr;
    }
    cout << ans - 1 << endl;
  }
  return 0;
}
