#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using pii = std::pair<long long, long long>;
using namespace std;
class CGuessYourWayOut {
 public:
  void solve(std::istream& in, std::ostream& out) {
    long long h, n;
    in >> h >> n;
    out << ans(h, n, 0) << "\n";
  }
  long long ans(long long h, long long n, long long lr) {
    long long val;
    if (h == 0) return 0;
    if (lr == 0) {
      if (n > (long long)pow(2, h - 1)) {
        return (long long)pow(2, h) +
               ans(h - 1, n - (long long)pow(2, h - 1), 0);
      } else {
        return 1 + ans(h - 1, n, 1);
      }
    } else {
      if (n > (long long)pow(2, h - 1)) {
        return 1 + ans(h - 1, n - (long long)pow(2, h - 1), 0);
      } else {
        return (long long)pow(2, h) + ans(h - 1, n, 1);
      }
    }
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  CGuessYourWayOut solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
