#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int small(int c, int k, int m) {
  int g = gcd(c, m);
  int start = k % m;
  while (start < 0) {
    start += g;
  }
  return start % g;
}
int main() {
  ios::sync_with_stdio(false);
  int la, ra, ta, lb, rb, tb;
  cin >> la >> ra >> ta >> lb >> rb >> tb;
  if (ra - la < rb - lb) {
    swap(ra, rb);
    swap(la, lb);
    swap(ta, tb);
  }
  int d = small(ta, la - lb, tb);
  int best = 0;
  best = max(best, rb - lb + 1 - d);
  d = small(ta, rb - ra, tb);
  best = max(rb - lb + 1 - d, best);
  d = small(ta, lb - la, tb);
  if (d + rb - lb + 1 <= ra - la + 1) best = rb - lb + 1;
  cout << best << "\n";
  return 0;
}
