#include using namespace std; #define rep(i, n) for( ll i = 0; i < n; i++ ) using ll = long long; int main() { ll A, B, a, b; cin >> A >> B >> a >> b; ll ma = A * B, ans; rep(i, ma + 1) { if( i % A == a && i % B == b) { ans = i; break; } } cout << ans << endl; }