#include <bits/stdc++.h>
using namespace std;
long long la, ra, ta, lb, rb, tb, r;
long long getInter() {
  if (ra < lb) return 0;
  if (rb < la) return 0;
  return min(ra, rb) - max(la, lb) + 1;
}
long long gcd(long long a, long long b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
int main() {
  r = 0;
  cin >> la >> ra >> ta >> lb >> rb >> tb;
  long long g = gcd(ta, tb);
  if ((ra - la) < (rb - lb)) {
    swap(ra, rb);
    swap(la, lb);
  }
  long long dif = la - lb;
  dif = dif / g * g;
  lb += dif;
  rb += dif;
  long long cr = getInter();
  r = max(r, cr);
  lb -= 3 * g;
  rb -= 3 * g;
  for (long long i = -2; i < 0; i++) {
    lb += g;
    rb += g;
    cr = getInter();
    r = max(r, cr);
  }
  dif = ra - rb;
  dif = dif / g * g;
  lb += dif + g;
  rb += dif + g;
  for (long long i = 1; i > -1; i--) {
    cr = getInter();
    r = max(r, cr);
    lb -= g;
    rb -= g;
  }
  cout << r;
  return 0;
}
