#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxyYW5kb20+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDx1bm9yZGVyZWRfbWFwPgojaW5jbHVkZSA8c3N0cmVhbT4KI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