#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  if (b == 0) {
    return a;
  }
  return gcd(b % a, a);
}
int main() {
  long long ra, la, ta, rb, lb, tb;
  cin >> la >> ra >> ta;
  cin >> lb >> rb >> tb;
  long long g = gcd(ta, tb);
  if (ta > tb) {
    long long j = la, k = ra, l = ta;
    la = lb;
    ra = rb;
    ta = tb;
    lb = j;
    rb = k;
    tb = l;
  }
  lb -= la;
  rb -= la;
  long long buff = ((lb + tb) % tb) - lb;
  lb += buff;
  rb += buff;
  ra -= la;
  la -= la;
  long long bdif = 0;
  long long nf = (lb % g) - lb;
  lb += nf;
  rb += nf;
  bdif = max(bdif, 1 + min(rb, ra) - max(lb, la));
  long long nl = ((lb + g - 1) % g) - g + 1;
  long long df = nl - lb;
  lb += df;
  rb += df;
  bdif = max(bdif, 1 + min(rb, ra) - max(lb, la));
  cout << bdif << endl;
}
