// #include using namespace std; using ll = long long; #define rep(i, n) for (int i=0; i<(int)(n); ++(i)) #define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i)) #define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i)) #define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i)) #define all(x) (x).begin(), (x).end() const int INF = (int)(1e9); int main() { int a, b, ai, bi; cin >> a >> b >> ai >> bi; if (a > b) { swap(a, b); swap(ai, bi); } int x = bi; while (x%a != ai) x += b; cout << x << endl; return 0; }