#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
string dfs(string s,ll lon){
    string t = "B";
    t = t + s;
    t = t + "P";
    t = t + s;
    t = t + "B";
    lon++;
    if(lon == n)
    return t;
    dfs(t,lon);
}

int main(){
    ll x;
    cin >> n >> x;
    string s = "BPPPB";
    ll lon = 1;
    string ans = "BPPPB";
    if(n != 1)
    ans = dfs(ans, lon);
    reverse(ans.begin(),ans.end());
    ll cnt = 0;
    for(ll i = 0; i < x; i++){
        if(ans[i] == 'P')
        cnt++;
    }
    cout << cnt << endl;
}