#include using namespace std; int main() { int A, B, a, b; cin >> A >> B >> a >> b; int x = 0; // cout << "aaa" << endl; while (true) { if (x % A == a && x % B == b) { cout << x << endl; break; } x++; } // cout << "aaa" << endl; return 0; }