#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
inline long long inter(long long a, long long b, long long c, long long d) {
  long long start = max(a, c);
  long long end = min(b, d);
  if (start > end) return 0;
  return (end - start + 1);
}
int main() {
  long long l1, l2, r1, r2, t1, t2;
  cin >> l1 >> r1 >> t1;
  cin >> l2 >> r2 >> t2;
  long long d1 = r1 - l1;
  long long d2 = r2 - l2;
  long long g = gcd(t1, t2);
  l1 %= g;
  l2 %= g;
  long long ans = 0;
  for (long long x : {l1 - g, l1, l1 + g}) {
    ans = max(ans, inter(x, x + d1, l2, l2 + d2));
  }
  cout << ans << endl;
  return 0;
}
