#include <stdio.h>

int main(){
int n,m,a[100];
while(scanf("%d%d",&n,&m)!=EOF){
	if(n==0)return 0;
int sum=0;
for(int i=n-m+1;i<=n;i++){
	int k=i;
	while(k%2==0){
		k/=2;
		sum++;
	}
}
printf("%d\n",sum);
}
	return 0;
}