#include using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) template inline bool chmax(T &a, T b) {return ((a < b) ? (a = b, true) : (false));} template inline bool chmin(T &a, T b) {return ((a > b) ? (a = b, true) : (false));} typedef long long ll; typedef pair P; int main() { ll A, B, a, b; cin >> A >> B >> a >> b; for(ll x = 1; x <= 100000000; x++) { if(x % A == a && x % B == b) { cout << x << endl; break; } } return 0; }