#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int n;
int la, ra, ta;
int lb, rb, tb;
int getgcd(int a, int b) { return b == 0 ? a : getgcd(b, a % b); }
int main() {
  cin >> la >> ra >> ta;
  cin >> lb >> rb >> tb;
  if (la > lb) {
    swap(la, lb);
    swap(ra, rb);
  }
  int g = getgcd(ta, tb);
  int x = (lb - la) / g;
  la += x * g;
  ra += x * g;
  int ans = 0;
  ans = max(ans, max(0, min(ra, rb) - lb + 1));
  la += g;
  ra += g;
  ans = max(ans, max(0, min(ra, rb) - la + 1));
  cout << ans << endl;
  return 0;
}
