#include <iostream>
using namespace std;
int calcu(int n, int k)
{
double ans=1.0;
if(n-k<k)
k=n-k;
for(int i=1; i<=k; i++)
ans*=1.0*(n+1-i)/i;
ans+=0.5;
return (int)ans;
}
int main()
{
int n,k;
while(cin>>n>>k)
{
int ans=0;
while(n)
{
int w=0,t=n;
while(t)
{
w++;
t/=2;
}
if(w>k)
ans+=calcu(w-1,k);
n-=(1<<(w-1));
k--;
if(k<0)
break;
}
cout<<ans<<endl;
}
return 0;
}