#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n-1);i>=0;i--) #define ALL(v) v.begin(),v.end() #define RALL(v) v.rbegin(),v.rend() template using V=vector; template using VV=V>; using u128=__int128_t; using ll=long long; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int p,q,y0,p0,q0,y; cin>>p>>q>>y0>>p0>>q0>>y; p0--,q0--; int a=p0,b=q0; a=(a-y0+y+p*100000)%p; b=(b-y0+y+q*100000)%q; a++,b++; cout<