#include <bits/stdc++.h>
using namespace std;
int main() {
  int h;
  long long int n;
  cin >> h >> n;
  long long int p = pow(2, h);
  long long int f = p - 1;
  f = f + n;
  long long int k = 0;
  int g = 0;
  int a[100];
  while (f != 0) {
    g++;
    a[g] = f % 2;
    f = f / 2;
  }
  int o = 0;
  for (long i = g - 1; i >= 1; i--) {
    if (a[i] == o)
      k = k + 1;
    else {
      k = k + p;
    }
    p = p / 2;
    o = 1 - a[i];
  }
  cout << k << endl;
}
