#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 3.141592653589793238462643383279502884;
const double EPS = 1e-9;
long long nod(long long a, long long b) {
  while (b != 0 && a != b) {
    if (a > b) {
      a = a % b;
      swap(a, b);
    } else {
      swap(a, b);
    }
  }
  return a;
}
int main() {
  long long la, ra, ta, stepa;
  long long lb, rb, tb, stepb;
  cin >> la >> ra >> ta;
  cin >> lb >> rb >> tb;
  stepa = ra - la;
  stepb = rb - lb;
  long long t = nod(ta, tb);
  long long maxCount = 0;
  long long diff = (lb - la) % t;
  if (diff < 0) {
    diff += t;
  }
  for (int i = -4; i <= 3; i++) {
    long long diff_i = diff + i * t;
    if (diff_i < 0) {
      diff_i = abs(diff_i);
      maxCount = max(maxCount, min(stepb, diff_i + stepa) - diff_i + 1);
    } else {
      maxCount = max(maxCount, min(stepa, diff_i + stepb) - diff_i + 1);
    }
  }
  diff = (rb - ra) % t;
  if (diff < 0) {
    diff += t;
  }
  for (int i = -4; i <= 3; i++) {
    long long diff_i = diff + i * t;
    if (diff_i < 0) {
      diff_i = abs(diff_i);
      maxCount = max(maxCount, min(stepa, diff_i + stepb) - diff_i + 1);
    } else {
      maxCount = max(maxCount, min(stepb, diff_i + stepa) - diff_i + 1);
    }
  }
  cout << maxCount;
  cout << endl;
  return 0;
}
