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

typedef long long ll;

ll A, B;

ll solve(ll a, ll b) {
    if(b == 0) return 1;
    int p;
    for(int i = 0; i <= 60; i++) {
        if(b < (1LL << i)) {
            p = i - 1;
            break;
        }
    }

    if(a >= (1LL << p)) {
        return solve(a ^ (1LL << p), b ^ (1LL << p));
    }

    b ^= (1LL << p);
    ll ret = 0;
    int x;
    for(int i = 0; i <= 60; i++) {
        if(b < (1LL << i)) {
            x = i - 1;
            break;
        }
    }
    ret += ((1LL << p) - a);
    ret += min((1LL << p), (1LL << (x + 1)) + (1LL << p) - a);
    return ret;
}

int main() {
    cin >> A >> B;
    cout << solve(A, B);
}
