#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const double exps = 1e-8;
const double pi = acos(-1.0);
const int maxn = 1e5 + 5;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
long long extendGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long r = extendGcd(b, a % b, x, y);
  long long t = x;
  x = y;
  y = t - a / b * y;
  return r;
}
long long ka, kb;
void solve(long long la, long long lb, long long ta, long long tb) {
  kb = 0, ka = 0;
  long long res = lb - la;
  if (res == 0) return;
  long long d = gcd(ta, tb);
  long long k;
  ta /= d;
  tb /= d;
  if (res > 0) {
    k = res / d;
    extendGcd(ta, tb, ka, kb);
    while (kb > 0 || ka < 0) {
      kb -= ta;
      ka += tb;
    }
    ka *= k;
    kb *= -k;
  } else {
    if ((-res) % d == 0)
      k = -res / d;
    else
      k = (-res / d) + 1;
    extendGcd(ta, tb, ka, kb);
    while (kb < 0 || ka > 0) {
      kb += ta;
      ka -= tb;
    }
    ka *= -k;
    kb *= k;
  }
}
void solve2(long long la, long long lb, long long ta, long long tb) {
  kb = 0, ka = 0;
  long long res = la - lb;
  if (res == 0) return;
  long long d = gcd(ta, tb);
  long long k;
  ta /= d;
  tb /= d;
  if (res > 0) {
    k = res / d;
    extendGcd(ta, tb, ka, kb);
    while (kb < 0 || ka > 0) {
      kb += ta;
      ka -= tb;
    }
    ka *= -k;
    kb *= k;
  } else {
    if ((-res) % d == 0)
      k = -res / d;
    else
      k = (-res / d) + 1;
    extendGcd(ta, tb, ka, kb);
    while (kb > 0 || ka < 0) {
      kb -= ta;
      ka += tb;
    }
    ka *= k;
    kb *= -k;
  }
}
int main() {
  long long la, ra, ta;
  long long lb, rb, tb;
  scanf("%lld%lld%lld", &la, &ra, &ta);
  scanf("%lld%lld%lld", &lb, &rb, &tb);
  long long ans = 0;
  solve(la, lb, ta, tb);
  long long l = max(la + ka * ta, lb + kb * tb),
            r = min(ra + ka * ta, rb + kb * tb);
  if (l <= r) ans = max(ans, r - l + 1);
  solve2(la, lb, ta, tb);
  l = max(la + ka * ta, lb + kb * tb), r = min(ra + ka * ta, rb + kb * tb);
  if (l <= r) ans = max(ans, r - l + 1);
  printf("%lld\n", ans);
  return 0;
}
