#include using namespace std; #define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr); #include using namespace atcoder; void solve() { vector R(3), M(3); for (int i = 0; i < 3; i++) { cin >> R[i] >> M[i]; } auto p = crt(R, M); if (p == make_pair(0LL, 0LL)) { cout << -1 << endl; } else if (p.first == 0) { cout << p.second << endl; } else { cout << p.first << endl; } } int main() { bokusunny; solve(); return 0; }