#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a[51];
  a[0] = 1;
  for (int i = 1; i < 50; i++) a[i] = a[i - 1] * 2;
  long long int n, m;
  cin >> n >> m;
  long long int cnt = n;
  int j = 0;
  for (int i = n - 1; i > -1; i--, j++) {
    j %= 2;
    int x = 0;
    if (m > a[i]) {
      x = 1;
      m -= a[i];
    }
    if (j != x) {
      cnt += (a[i] * 2) - 1;
      j--;
    }
  }
  cout << cnt;
}
