#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
int solve(int a, int b, int x, int y) { return min(b, y) - max(a, x) + 1; }
int main() {
  int la, ra, ta, lb, rb, tb;
  while (~scanf("%d%d%d%d%d%d", &la, &ra, &ta, &lb, &rb, &tb)) {
    la++, ra++, lb++, rb++;
    int item = gcd(ta, tb);
    if (ta == tb) {
      printf("%d\n", solve(la, ra, lb, rb));
      continue;
    }
    int m, ans;
    if (ra <= rb) {
      m = (rb - ra) / item;
      la += m * item;
      ra += m * item;
      ans = 0;
      ans = max(ans, solve(la, ra, lb, rb));
      ans = max(ans, solve(la + item, ra + item, lb, rb));
    } else {
      m = (ra - rb) / item;
      lb += m * item;
      rb += m * item;
      ans = 0;
      ans = max(ans, solve(la, ra, lb, rb));
      ans = max(ans, solve(la, ra, lb + item, rb + item));
    }
    printf("%d\n", ans);
  }
}
