#include <bits/stdc++.h>
using namespace std;
int l[2];
int r[2];
int t[2];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  for (int i = 0; i < 2; ++i) cin >> l[i] >> r[i] >> t[i];
  int g = gcd(t[0], t[1]);
  int len[2] = {0};
  len[0] = r[0] - l[0] + 1;
  len[1] = r[1] - l[1] + 1;
  l[0] %= g;
  l[1] %= g;
  int result = 0;
  int tmp = min(l[0] + len[0], l[1] + len[1]) - max(l[0], l[1]);
  result = max(result, tmp);
  if (l[0] < l[1])
    l[0] += g;
  else
    l[1] += g;
  tmp = min(l[0] + len[0], l[1] + len[1]) - max(l[0], l[1]);
  result = max(result, tmp);
  cout << result << endl;
  return 0;
}
