#include <bits/stdc++.h>
using namespace std;
long long la, lb, ra, rb, ta, tb;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long calc(long long la, long long ra, long long lb, long long rb) {
  return max(0ll, min(ra, rb) - max(la, lb) + 1);
}
int main() {
  while (scanf("%lld%lld%lld", &la, &ra, &ta) != EOF) {
    scanf("%lld%lld%lld", &lb, &rb, &tb);
    if (la > lb) {
      swap(la, lb);
      swap(ra, rb);
      swap(ta, tb);
    }
    long long g = gcd(ta, tb);
    long long gap = ra - la;
    la += ((lb - la) / g) * g;
    ra = la + gap;
    printf("%lld\n", max(calc(la, ra, lb, rb), calc(la + g, ra + g, lb, rb)));
  }
  return 0;
}
