#include <bits/stdc++.h>
#define MAX 10000
using namespace std;


int main(){
	int res[MAX];
	int n,m,k,len,i,sum;
	while(cin>>n>>m){
		if(!n && !m)
			break;
		sum = 0;
		for(int i = n; i >= n-m+1; i--){
			int k = i;
			while(k % 2 == 0){
				sum++;
				k /= 2;
			}
		}	

		cout<<sum<<endl;
	}

}