#include <iostream>
using namespace std;

int birnaryTree(int m,int n){
    if(m<=n){
        return 1+birnaryTree(2*m, n)+birnaryTree(2*m+1, n);
    }else{
        return 0;
    }
}
int main() {
    int m,n;
    while(cin>>m>>n){
        if(m==0&&n==0) break;
        cout<<birnaryTree(m, n)<<endl;
    }
    return 0;
}