#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int getInt(int la, int ra, int lb, int rb) {
  int r = min(ra, rb);
  int l = max(la, lb);
  return max(0, r - l + 1);
}
int main(void) {
  int la, ra, ta, lb, rb, tb;
  cin >> la >> ra >> ta >> lb >> rb >> tb;
  int d = gcd(tb, ta);
  if (la < lb) {
    swap(la, lb);
    swap(ra, rb);
  }
  int diff = la - lb;
  int move = (diff / d) * d;
  lb += move;
  rb += move;
  int ans = getInt(la, ra, lb, rb);
  lb += d;
  rb += d;
  ans = max(ans, getInt(la, ra, lb, rb));
  cout << ans << endl;
  return 0;
}
