#include <bits/stdc++.h>
using namespace std;
long long int visits(long long h, long long n, long long ans, int side) {
  if (h == 1 && side > 0) {
    if (n == 1)
      return ans + 2;
    else
      return ans + 1;
  }
  if (h == 1 && side <= 0) {
    if (n == 1)
      return ans + 1;
    else
      return ans + 2;
  }
  long long b = (long long)1 << h;
  long long k = b >> 1;
  if (n > k && side <= 0) {
    return visits(h - 1, n - k, ans + b, -1);
  } else if (n > k && side > 0) {
    return visits(h - 1, n - k, ans + 1, -1);
  } else if (n <= k && side <= 0) {
    return visits(h - 1, n, ans + 1, 1);
  } else {
    return visits(h - 1, n, ans + b, 1);
  }
}
int main() {
  long long h, n;
  cin >> h;
  cin >> n;
  long long b = 1;
  long long ans = 0;
  ans = visits(h, n, ans, -1);
  cout << ans;
  return 0;
}
