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

const int N=200008;
int a[N], b[N], ta, tb;
int main()
{
	cin.sync_with_stdio(0);
	long long A,B;
	cin >> A >> B;
	if (A == B) {cout << 1 << endl; return 0;}
	if (A > B) swap(A, B);
	ta = tb = 0;
	while (A)
	{
		a[ta++] = A % 2;
		A >>= 1;
	}
	while (B)
	{
		b[tb++] = B % 2;
		B >>= 1;
	}
	int r = 0;
	for (int i = 0; i < max(ta, tb); i++)
		if (a[i] != b[i]) r = i;
	for (int i = r; i >= 0; i--)
		A = A * 2 + a[i], B = B * 2 + b[i];
	int pos = -1;
	for (int i = 0; i < r; i++) if (b[i] == 1) pos = i;
	long long R = (1ll << r) + (1ll << pos + 1) - 1;
	long long T = 1ll << r;
	long long L = A + T;
	long long ans = T - A;
	if (R < L) ans += R - T + 1, ans += T * 2 - A - T; else ans += T;
	cout << ans << endl;	
}
