#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  long long la, ra, ta, lb, rb, tb, l, r, m, ans = 0;
  cin >> la >> ra >> ta >> lb >> rb >> tb;
  if (ta == tb) {
    l = max(la, lb);
    r = min(ra, rb);
    ans = r - l + 1;
  } else {
    if (rb < ra) {
      swap(la, lb);
      swap(ra, rb);
      swap(ta, tb);
    }
    m = gcd(ta, tb);
    la = la + (rb - ra) - (rb - ra) % m;
    ra = ra + (rb - ra) - (rb - ra) % m;
    l = max(la, lb);
    r = min(ra, rb);
    ans = max(ans, r - l + 1);
    la += m;
    ra += m;
    l = max(la, lb);
    r = min(ra, rb);
    ans = max(ans, r - l + 1);
  }
  cout << ans;
  return 0;
}
