#include <bits/stdc++.h>
using namespace std;
long long h, n, l, r, m, ans;
stack<pair<pair<long long, long long>, pair<int, int>>> Stack;
long long pw(long long a, long long b) {
  long long ret = 1;
  while (b > 0) {
    if (b & 1) ret *= a;
    a *= a;
    b >>= 1;
  }
  return ret;
}
int main() {
  cin >> h >> n;
  Stack.push({{1, pw(2, h)}, {true, 0}});
  while (!Stack.empty()) {
    pair<pair<long long, long long>, pair<int, int>> cur = Stack.top();
    Stack.pop();
    l = cur.first.first, r = cur.first.second;
    int f = cur.second.first, lev = cur.second.second;
    if (n < l or n > r) {
      ans += pw(2, h + 1 - lev) - 1;
      continue;
    }
    if (l == r) {
      if (l == n)
        break;
      else {
        ans++;
        continue;
      }
    }
    m = l + r >> 1;
    if (f) {
      ans++;
      Stack.push({{m + 1, r}, {true, lev + 1}});
      Stack.push({{l, m}, {false, lev + 1}});
    } else {
      ans++;
      Stack.push({{l, m}, {false, lev + 1}});
      Stack.push({{m + 1, r}, {true, lev + 1}});
    }
  }
  cout << ans << endl;
  return 0;
}
