#include <bits/stdc++.h>
using namespace std;
const int base = 1000100000;
const int base_digits = 9;
clock_t start_time, end_time;
inline float ellapse() { return (clock() - start_time) * 1.0 / CLOCKS_PER_SEC; }
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b % 2 == 1) ret = (ret * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return ret;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long sum[52], poweroftwo[52];
int main() {
  sum[0] = 1;
  poweroftwo[0] = 1;
  for (int i = 1; i < 52; i++) {
    poweroftwo[i] = poweroftwo[i - 1] * 2;
    sum[i] = sum[i - 1] + poweroftwo[i];
  }
  long long n, h;
  cin >> h >> n;
  long long target = n + sum[h - 1], T = target;
  vector<int> str;
  while (target != 1) {
    if (target % 2 == 1)
      str.push_back(1);
    else
      str.push_back(0);
    target /= 2;
  }
  reverse(str.begin(), str.end());
  int length = str.size();
  int flag = 0;
  long long total = 0;
  for (int i = 0; i < length; i++) {
    if (str[i] == flag) {
      total++;
      flag ^= 1;
    } else
      total += 1 + sum[h - i - 1];
  }
  cout << total << endl;
  return 0;
}
