#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=4e6 + 10;
const ll mod= 1e9+7;
const ll inf=1e18+77;
//#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll n, k, q;
ll cnt=0;
void place(ll pos, ll j){
cnt=pos%mod;
k--;
if(k==0)return;
for(int i=max(n-60,j+1); i<=n-1; i++){
ll st=n-1-i;
if(st>60)continue;
st=(1ll<<st);
if(k-(st)>=0){
k-=(st-1);
place((pos+(1ll<<i))%mod, i);
break;
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll tt;
//cin>>tt;
tt=1;
while(tt--){
ll x, y;
cin>>n>>k;
place(1, -1);
cout<<cnt<<endl;
}
return 0;
}