#include using namespace std; using ll = long long; using ld = long double; template using vc = vector; template using vvc = vc>; void solve(); int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll t = 1; // cin >> t; for (int i = 1; i <= t; i++) solve(); return 0; } void solve() { ll A, B, a, b; cin >> A >> B >> a >> b; for (int i = 0; i <= A * B; i++) { if (i % A == a && i % B == b) { cout << i << endl; return; } } }