#include <bits/stdc++.h>
using namespace std;
long long __gcd(long long a, long long b) {
  long long rem;
  while (b) {
    rem = a % b;
    a = b;
    b = rem;
  }
  return a;
}
long long find_intersection(long long x1, long long y1, long long x2,
                            long long y2) {
  long long x = max(x1, x2);
  long long y = min(y1, y2);
  return (x <= y) ? (y - x + 1) : 0;
}
int main() {
  long long t, n, i, j, k, l, m;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long p;
  t = 1;
  while (t--) {
    long long la, ra, lb, rb, ta, tb;
    cin >> la >> ra >> ta;
    cin >> lb >> rb >> tb;
    if (__gcd(ta, tb) == 1)
      cout << min(rb - lb + 1, ra - la + 1) << '\n';
    else {
      long long x = __gcd(ta, tb);
      ta = x;
      tb = x;
      if (la > lb) {
        long long tmp = la;
        la = lb;
        lb = tmp;
        tmp = ra;
        ra = rb;
        rb = tmp;
      }
      long long ans = 0;
      x = (lb - la) / ta;
      long long nl = la + x * ta;
      long long nr = ra + x * ta;
      ans = max(ans, find_intersection(nl, nr, lb, rb));
      x++;
      nl = la + x * ta;
      nr = ra + x * ta;
      ans = max(ans, find_intersection(nl, nr, lb, rb));
      cout << ans << '\n';
    }
  }
  return 0;
}
