#include <bits/stdc++.h>
using namespace std;
const long long oo = 2e9, mod = 1000000007;
long long h, n;
long long traverse(long long height, long long left, long long right,
                   long long cmd) {
  if (height == 1) {
    return 0;
  }
  long long mid = (right + left) / 2;
  if (cmd) {
    if (n <= mid) {
      return 1 + traverse(height - 1, left, mid, !cmd);
    } else {
      return (1LL << (height - 1)) + traverse(height - 1, mid + 1, right, cmd);
    }
  } else {
    if (n > mid) {
      return 1 + traverse(height - 1, mid + 1, right, !cmd);
    } else {
      return (1LL << (height - 1)) + traverse(height - 1, left, mid, cmd);
    }
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin >> h >> n;
  cout << traverse(h + 1, 1, pow(2, h), 1) << endl;
  return 0;
}
