#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T parse(const string& s) {
  T x;
  stringstream ss(s);
  ss >> x;
  return x;
}
long long common(long long l1, long long r1, long long l2, long long r2) {
  if (l1 > l2) {
    swap(l1, l2);
    swap(r1, r2);
  }
  long long r = min(r1, r2);
  if (r >= l2)
    return r - l2 + 1;
  else
    return 0;
}
long long gcd(long long a, long long b) {
  if (b) return gcd(b, a % b);
  return a;
}
int main() {
  long long l1, l2, r1, r2, t1, t2;
  cin >> l1 >> r1 >> t1;
  cin >> l2 >> r2 >> t2;
  if (t1 > t2) {
    swap(t1, t2);
    swap(l1, l2);
    swap(r1, r2);
  }
  if (t1 == t2)
    cout << common(l1, r1, l2, r2);
  else {
    long long res = 0;
    long long len = r1 - l1;
    long long d = gcd(t1, t2);
    long long b = (((l2 - l1) % t2) + t2) % t2;
    long long k = b / d;
    l1 = (l1 + (k - 1) * d) % t2;
    for (int i = 0; i < (3); ++i) {
      res = max(res, common(l1, l1 + len, l2, r2));
      l1 = (l1 + d) % t2;
    }
    cout << res;
  }
  return 0;
}
