#include // #include // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector; using vvll = vector>; using mll = map; using qll = queue; using P = pair; using vp = vector

; using vs = vector; template inline istream& operator>>(istream& i, vector& v) { rep(j, v.size()) i >> v[j]; return i; } template inline istream& operator>>(istream& i, pair& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template void chmax(T& a, const T& b) { if (a < b) a = b; } template void chmin(T& a, const T& b) { if (b < a) a = b; } ll mod_pow(ll x, ll n, ll mod) { if (n == 0) return 1; ll res = mod_pow(x * x % mod, n / 2, mod); if (n & 1) res *= x; res %= mod; return res; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll ext_gcd(ll a, ll b, ll& p, ll& q) { if (b == 0) { p = 1; q = 0; return a; } ll d = ext_gcd(b, a % b, q, p); q -= a / b * p; return d; } P crt(ll b1, ll m1, ll b2, ll m2) { ll p, q; ll d = ext_gcd(m1, m2, p, q); if ((b2 - b1) % d != 0) return {0, -1}; ll m = lcm(m1, m2); ll tmp = (b2 - b1) / d * p % (m2 / d); ll r = mod(b1 + m1 * tmp, m); return make_pair(r, m); } signed main() { init(); ll x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; P p = crt(x1, y1, x2, y2); P ans = crt(p.first, p.second, x3, y3); if (p.second == -1 or ans.second == -1) { COUT(-1); return 0; } COUT(ans.first); return 0; }