#include <bits/stdc++.h>
using namespace std;
int main() {
  int la, ra, ta, lb, rb, tb;
  cin >> la >> ra >> ta >> lb >> rb >> tb;
  if (la > lb) {
    int c;
    c = la;
    la = lb;
    lb = c;
    c = ra;
    ra = rb;
    rb = c;
    c = ta;
    ta = tb;
    tb = c;
  }
  int a, b;
  a = ta;
  b = tb;
  while (a * b != 0) {
    if (a >= b) {
      a %= b;
    } else {
      b %= a;
    }
  }
  a = a + b;
  int l = lb - la;
  l -= (l % a);
  la += l;
  ra += l;
  int sum1, sum2;
  sum1 = min(ra, rb) - lb + 1;
  la += a;
  ra += a;
  sum2 = min(ra, rb) - la + 1;
  if (max(sum1, sum2) < 0) sum1 = 0;
  cout << max(sum1, sum2);
  return 0;
}
