#include<bits/stdc++.h> #define forn(i, n) for (int i = 0 ; i < int(n) ; i++) #define fore(i, s, t) for (int i = s ; i < (int)t ; i++) #define fi first #define se second #define all(x) x.begin(),x.end() #define pf2(x,y) printf("%d %d ",x,y) #define pf(x) printf("%d ",x) #define each(x) for(auto it:x) cout<<it<<endl; #define pii pair<int,int> #define sc(x) scanf("%d",&x) using namespace std; typedef long long ll; const int maxn=2e5+5; const int maxm=2e5+5; const int inf=1e9; ll len(ll l,ll r){ return r-l; } int main(){ ll la,ra,ta,lb,rb,tb; cin>>la>>ra>>ta>>lb>>rb>>tb; ll g=__gcd(ta,tb),ans=0; if(abs(la-lb)%g) { ll d=(lb-la)%g; if(d<0) d+=g; ans=max(ans,min(d+len(lb,rb),len(la,ra))-max(0ll,d)+1); d=g-d; ans=max(ans,min(len(lb,rb),d+len(la,ra))-max(0ll,d)+1); } else { ans=min(len(la,ra)+1,len(lb,rb)+1); } cout<<ans<<endl; }