#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int la, ra, ta;
  int lb, rb, tb;
  scanf("%d%d%d%d%d%d", &la, &ra, &ta, &lb, &rb, &tb);
  if (la < lb) {
    swap(la, lb);
    swap(ta, tb);
    swap(ra, rb);
  }
  int ans = 0;
  int g = gcd(ta, tb), zzt = (la - lb) / g;
  la -= zzt * g;
  ra -= zzt * g;
  ans = max(ans, min(ra, rb) - max(la, lb) + 1);
  la -= g;
  ra -= g;
  ans = max(ans, min(ra, rb) - max(la, lb) + 1);
  printf("%d", ans);
}
