#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll l[2], r[2], t[2];
int main() {
  int i;
  for (i = 0; i < 2; i++) {
    cin >> l[i] >> r[i] >> t[i];
  }
  if (t[0] < t[1]) {
    swap(l[0], l[1]);
    swap(r[0], r[1]);
    swap(t[0], t[1]);
  }
  ll x = gcd(t[0], t[1]), y = l[1] - l[0];
  if (y < 0) (y += t[0]) %= t[0];
  ll a = y % x - x + t[0], b = y % x;
  ll c = r[1] - l[1] + 1, d = r[0] - l[0] + 1;
  ll ans = max(min(b + c, d) - b, min(a + c - t[0], r[0] - l[0] + 1));
  cout << max(ans, 0LL) << endl;
}
