#include <bits/stdc++.h>
using namespace std;
long long mygcd(long long a, long long b) {
  if (!b) return a;
  return mygcd(b, (a % b));
}
int main() {
  ios::sync_with_stdio(0);
  long long la, ra, ta, lb, rb, tb;
  cin >> la >> ra >> ta >> lb >> rb >> tb;
  if (tb < ta) {
    swap(la, lb);
    swap(ra, rb);
    swap(ta, tb);
  }
  long long lab = min(la, lb);
  la -= lab;
  lb -= lab;
  ra -= lab;
  rb -= lab;
  long long g = mygcd(ta, tb);
  long long offs;
  if (lb >= la) {
    long long k = (lb - la) / ta;
    offs = lb - (la + (k * ta));
  } else {
    long long k = ((la - lb) / tb) + (((la - lb) % tb) > 0ll);
    offs = (lb + (k * tb)) - la;
  }
  long long k = offs / g;
  long long minoff = offs - (k * g);
  k = (tb - offs) / g;
  long long maxoff = offs + (k * g);
  long long minoff_score = max(0ll, min(ra - la + 1 - minoff, rb - lb + 1));
  long long maxoff_score =
      max(0ll, min(ra - la + 1, rb - lb + 1 - (tb - maxoff)));
  cout << max(minoff_score, maxoff_score);
  return 0;
}
