#include #include #define M_PI 3.14159265358979323846 // pi using namespace std; using namespace chrono; using namespace atcoder; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef pair P; typedef tuple t3; typedef tuple t4; typedef tuple t5; typedef tuple t6; typedef tuple tts; #define rep(a,n) for(ll a = 0;a < n;a++) #define rrep(a,n) for(int a = n-1;a >= 0;a--) #define repi(a,b,n) for(int a = b;a < n;a++) template void chmax(T& a, T v) { a = max(a, v); } template void chcmpmax(map& a, T key, TVal value) { if (a.count(key)) { chmax(a[key], value); } else { a[key] = value; } } template void chcmpmax(unordered_map& a, T key, TVal value) { auto it = a.find(key); if (it == a.end()) { a[key] = value; } else { if (it->second < value) { it->second = value; } } } template void chmin(T& a, T v) { a = min(a, v); } template void chcmpmin(map& a, T key, TVal value) { if (a.count(key)) { chmin(a[key], value); } else { a[key] = value; } } int main() { vector xs(3), ys(3); rep(i, 3) { cin >> xs[i] >> ys[i]; } auto ans = atcoder::crt(xs, ys); if (ans == P{0,0}) { cout << -1 << endl; } else { if (ans.first == 0) { cout << ans.second << endl; } else { cout << ans.first << endl; } } return 0; }