#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f, gcd, aa, bb, cc, dd, ee, ff;
long long int gx(long long int asd, long long int dsa) {
  if (dsa == 0) return asd;
  return gx(dsa, asd % dsa);
}
long long int chk(long long int q, long long int w, long long int r,
                  long long int t) {
  if (w < r) return 0;
  if (w >= r && w <= t) {
    if (q < r)
      return w - r + 1;
    else
      return w - q + 1;
  }
  if (w > t) {
    if (q < r)
      return t - r + 1;
    else if (q >= r && q <= t)
      return t - q + 1;
    else
      return 0;
  }
}
int main() {
  cin >> a >> b >> c >> d >> e >> f;
  gcd = gx(c, f);
  aa = a;
  if (d > aa) aa = d;
  if ((aa - a) % c != 0) aa += c - (aa - a) % c;
  bb = d + (aa - d) / gcd * gcd;
  cc = chk(bb, bb + e - d, aa, aa + b - a);
  dd = d;
  if (a > dd) dd = a;
  if ((dd - d) % f != 0) dd += f - (dd - d) % f;
  ee = a + (dd - a) / gcd * gcd;
  ff = chk(ee, ee + b - a, dd, dd + e - d);
  if (cc > ff)
    cout << cc;
  else
    cout << ff;
}
