#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int intersect(int la, int ra, int lb, int rb) {
  return max(0, min(ra + 1, rb + 1) - max(la, lb));
}
int main() {
  int la, ra, ta, lb, rb, tb;
  cin >> la >> ra >> ta;
  cin >> lb >> rb >> tb;
  int g = gcd(ta, tb);
  int steps = (la - lb % g + g) / g;
  int step_before = lb % g + g * (steps - 1);
  int step_after = step_before + g;
  cout << max(intersect(la, ra, step_before, step_before + rb - lb),
              intersect(la, ra, step_after, step_after + rb - lb))
       << endl;
}
