#include <iostream>
using namespace std;
int m, n;
int main() {
while (cin >> m >> n) {
if (n == 0 && m == 0) break;
long long l = 2 * m;
long long r = 2 * m + 1;
int res = 1;
int level = 1; //每一层有多少个结点
while (r <= n) { //边界条件
level *= 2;
res += level;
l = l * 2;
r = r * 2 + 1;
}
if (l <= n) res = res + n - l + 1; //加上最后一层结点
cout << res << endl;
}
return 0;
}