#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
long long solve(long long l1, long long r1, long long t1, long long l2,
                long long r2, long long t2) {
  r1 -= l1;
  r2 -= l2;
  l2 += l1 * t2;
  l2 -= l1;
  l2 %= t2;
  long long g = gcd(t1, t2);
  l2 %= g;
  long long L = l2, R = min(r1, l2 + r2);
  return max(0LL, R - L);
}
int main() {
  long long l1, r1, t1, l2, r2, t2;
  cin >> l1 >> r1 >> t1;
  cin >> l2 >> r2 >> t2;
  r1++;
  r2++;
  cout << max(solve(l1, r1, t1, l2, r2, t2), solve(l2, r2, t2, l1, r1, t1))
       << endl;
  return 0;
}
