#include <iostream>
using namespace std;
int Q(int a,int b,int answer)
{
    if(a*2==b)
    {
        return answer+2;
    }
    else if(2*a+1==b)
    {
        return answer+3;
    } 
    else if(2*a>b)return answer+1;
    else 
    {
        return Q(2*a,b,answer)+Q(2*a+1,b,answer)+1;
    }
}


int main() {
    int a, b;//求a子树结点个数
    while (cin >> a >> b) { 
        if(a==0&&b==0)break;
        cout<<Q(a,b,0)<<endl;
    }
}