#include <bits/stdc++.h>
inline long long cmmdc(long long a, long long b) {
  long long r;
  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline void it(long long &a, long long &b) {
  long long aux;
  aux = a;
  a = b;
  b = aux;
}
inline long long min2(long long a, long long b) { return a < b ? a : b; }
int main() {
  long long la, ra, ta, lb, rb, tb, i, cm, aux;
  scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &la, &ra, &ta, &lb, &rb, &tb);
  cm = cmmdc(ta, tb);
  if (la > lb) {
    it(la, lb);
    it(ra, rb);
    it(ta, tb);
  }
  long long k = (lb - la) / cm;
  la += cm * k;
  ra += cm * k;
  long long r1 = 0, r2 = 0;
  if (ra >= lb) {
    r1 = min2(ra, rb) - lb + 1;
  }
  la += cm;
  ra += cm;
  if (rb >= la) {
    r2 = min2(ra, rb) - la + 1;
  }
  if (r1 < r2) r1 = r2;
  printf("%I64d", r1);
  return 0;
}
