#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const int up = 1e5 + 5;
int la, ra, ta, lb, rb, tb;
int gcd(int x, int y) {
  if (x == 0 || y == 0) {
    return x + y;
  }
  int r = x % y;
  while (r) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> la >> ra >> ta;
  cin >> lb >> rb >> tb;
  if (lb < la) {
    swap(la, lb);
    swap(ra, rb);
    swap(ta, tb);
  }
  int g = gcd(ta, tb);
  int rem = (lb - la) % g;
  int res = 0;
  if (rem != 0) {
    res = max(res, min(g - rem + ra - la, rb - lb) - (g - rem) + 1);
    res = max(res, min(ra - la, rem + rb - lb) - rem + 1);
  } else {
    res = max(res, min(ra - la, rb - lb) + 1);
  }
  cout << res << endl;
  return 0;
}
