#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
vector<long long> v;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  long long num = (1ll << n) - 1 + m;
  while (num) {
    v.push_back(num);
    num = (num >> 1);
  }
  int len = v.size();
  bool L = 1;
  for (int i = len - 1; i >= 1; i--) {
    if ((L == 1) && (v[i] << 1) == v[i - 1]) {
      ans++;
      L = 0;
    } else if ((L == 0) && (v[i] << 1 | 1) == v[i - 1]) {
      ans++;
      L = 1;
    } else {
      ans += (1ll << i);
    }
  }
  cout << ans;
  return 0;
}
