#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long int N = 100005;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n >> k;
    m = (1ll << (n - 1));
    char ch = 'L';
    i = 0;
    while (m) {
      if (i + m < k) {
        i = i + m;
        if (ch == 'R') {
          ans++;
          ch = 'L';
        } else
          ans += 2 * m;
      } else {
        if (ch == 'L') {
          ans++;
          ch = 'R';
        } else
          ans += 2 * m;
      }
      m = m / 2;
    }
    cout << ans << '\n';
  }
  return 0;
}
