#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(long long i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000007 int main(){ int x1,y1,x2,y2,x3,y3; cin>>x1>>y1; cin>>x2>>y2; cin>>x3>>y3; if(y1>y2){ swap(y1,y2); swap(x1,x2); } if(y2>y3){ swap(y2,y3); swap(x2,x3); } rep(i,0,60000000){ long long a = (long long)y3*i+x3; if(a%y1==x1&&a%y2==x2){ cout << a << endl; return 0; } } cout << -1 << endl; return 0; }