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

#define int long long
#define inf 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1LL; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rep1(i, n) for(int i = 1LL; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

class Dinic {
public:
  vector<vector<pair<int, int>>> v;
  vector<int> e;

  vector<int> k;
  vector<int> j;

  void init(int n) {
    v = vector<vector<pair<int, int>>>(n);
    e = vector<int>();
    k = vector<int>(n);
    j = vector<int>(n);
  }
  void add_edge(int a, int b, int atob, int btoa = 0) {
    v[a].push_back(make_pair(b, e.size()));
    e.push_back(atob);
    v[b].push_back(make_pair(a, e.size()));
    e.push_back(btoa);
  }
  void dyk(int s) {
    for(auto& i : k) {
      i = inf;
    }
    queue<pair<int, int>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()) {
      int w = pq.front().first;
      int b = pq.front().second;
      pq.pop();
      if(k[b] > w) {
        k[b] = w;
        for(auto i : v[b]) {
          if(e[i.second] > 0) {
            pq.push(make_pair(w + 1LL, i.first));
          }
        }
      }
    }
  }
  int dfs(int s, int t, int p, int c) {
    if(p == t) {
      return c;
    }
    int all = 0;
    while(c > all && j[p] < v[p].size()) {
      if(k[v[p][j[p]].first] == k[p] + 1LL) {
        int r = dfs(s, t, v[p][j[p]].first, min(c - all, e[v[p][j[p]].second]));
        e[v[p][j[p]].second] -= r;
        e[v[p][j[p]].second ^ 1LL] += r;
        if(r < c - all) {
          j[p]++;
        }
        all += r;
      }
      else {
        j[p]++;
      }
    }
    return all;
  }
  int solve(int s, int t) {
    int all = 0;
    while(1LL) {
      dyk(s);
      for(auto& i : j) {
        i = 0;
      }
      int r = dfs(s, t, s, inf);
      if(r == 0) {
        return all;
      }
      all += r;
    }
  }
};

map<pair<pair<int, int>, pair<int, int>>, int> mp;

int solve(int a1, int a2, int b1, int b2, int n) {
  int a1n = a1 & ((1LL << n) - 1);
  int a1t = a1 & (1LL << n);
  int a2n = a2 & ((1LL << n) - 1);
  int a2t = a2 & (1LL << n);
  int b1n = b1 & ((1LL << n) - 1);
  int b1t = b1 & (1LL << n);
  int b2n = b2 & ((1LL << n) - 1);
  int b2t = b2 & (1LL << n);
  if(mp.find(make_pair(make_pair(a1, a2), make_pair(b1, b2))) == mp.end()) {
    int w;
    if(n == 0) {
      if(a1 == a2 && a2 == b1 && b1 == b2) {
        w = 1;
      }
      else {
        w = 2;
      }
    }
    else {
      if(a1 != b1) {
        if(a2t != b1t) {
          w = solve(a1n, a2n, a1n, a2n, n - 1) + (1LL << n) - b1n;
        }
        else {
          if(a1t != a2t) {
            w = 1LL << n + 1;
          }
          else {
            w = solve(a1n, a2n, b1n, (1LL << n) - 1, n - 1) + (1LL << n);
          }
        }
      }
      else {
        if(a1t == a2t) {
          w = solve(a1n, a2n, a1n, a2n, n - 1);
        }
        else {
          if(a2n < a1n - 1) {
            w = solve(a1n, (1LL << n) - 1, a1n, (1LL << n) - 1, n - 1) + solve(0, a2n, a1n, (1LL << n) - 1, n - 1);
          }
          else {
            w = solve(a1n, (1LL << n) - 1, a1n, (1LL << n) - 1, n - 1) + (1LL << n);
          }
        }
      }
    }
    mp[make_pair(make_pair(a1, a2), make_pair(b1, b2))] = w;
  }
  return mp[make_pair(make_pair(a1, a2), make_pair(b1, b2))];
}

signed main() {
  int a, b;
  cin >> a >> b;
  cout << solve(a, b, a, b, 62) << endl;
}


Measured memory_bytes: 256