#include <bits/stdc++.h>
using namespace std;
long long n, h;
long long tot;
long long poww(long long a, long long b) {
  long long res = 1;
  while (b--) {
    res *= a;
  }
  return res;
}
long long solve_right(long long level, long long req);
long long solve_left(long long level, long long req) {
  if (level == h - 1) {
    if (req == 1) return 1;
    return 2;
  }
  long long num = poww(2, h - level - 1);
  if (num < req) {
    return num * 2 + solve_left(level + 1, req - num);
  } else {
    return 1 + solve_right(level + 1, req);
  }
}
long long solve_right(long long level, long long req) {
  if (level == h - 1) {
    if (req == 2) return 1;
    return 2;
  }
  long long num = poww(2, h - level - 1);
  if (num >= req) {
    return num * 2 + solve_right(level + 1, req);
  } else {
    return 1 + solve_left(level + 1, req - num);
  }
}
int main() {
  cin >> h >> n;
  tot = poww(2, h);
  long long res = solve_left(0, n);
  cout << res;
  return 0;
}
