#include <bits/stdc++.h>
const long long N = 200010;
using namespace std;
long long bi(long long a) {
  if (a == 0) return 1;
  long long xddd = bi(a / 2);
  return a % 2 ? xddd * xddd * 2 : xddd * xddd;
}
long long xd(long long grado, long long pos) {
  if (grado == 1) {
    return pos;
  }
  long long aea = bi(grado - 1);
  if (pos <= aea) {
    return xd(grado - 1, aea - pos + 1);
  } else {
    return xd(grado - 1, pos - aea) + aea;
  }
}
long long dp(long long grado, long long pos) {
  if (grado == 1) {
    if (pos == 1)
      return 2;
    else
      return 3;
  }
  return dp(grado - 1, (pos + 1) / 2) + xd(grado, pos);
}
int main() {
  long long h, k;
  cin >> h >> k;
  cout << dp(h, k) - 1 << endl;
  return 0;
}
