#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
#include <sstream>
#include <istream>
#include <iterator>
#include <numeric>
#include <tuple>
#include <cassert>
using namespace std;

long long gcd(long long a, long long b)
{
	return b == 0 ? a : gcd(b, a % b);
}

long long intersect_length(long long l0, long long r0, long long l1, long long r1)
{
	if (l0 > l1)
	{
		swap(l0, l1);
		swap(r0, r1);
	}

	long long d0 = r0 - l0 + 1;
	long long d1 = r1 - l1 + 1;

	d0 -= (l1 - l0);
	d0 = max(0ll, d0);

	return min(d0, d1);
}

int main()
{
	long long l[2], r[2], t[2], d[2];
	for (int i = 0; i < 2; i++)
	{
		cin >> l[i] >> r[i] >> t[i];
		d[i] = r[i] - l[i] + 1;
	}

	if (l[0] == l[1] || gcd(t[0], t[1]) == 1)
	{
		cout << min(d[0], d[1]);
		return 0;
	}

	int steps = 0;
	long long ans = 0;
	while (steps < 500000000)
	{
		ans = max(ans, intersect_length(l[0], r[0], l[1], r[1]));

		if (l[0] < l[1])
		{
			l[0] += t[0];
			r[0] += t[0];
		}
		else if (l[1] < l[0])
		{
			l[1] += t[1];
			r[1] += t[1];
		}
		else
			break;

		steps++;
	}

	cout << ans;
}