#include using namespace std; using ll = long long; int main(){ int A, B, a, b; cin >> A >> B >> a >> b; for (int i = 0; i <= A * B; i++) { if (i % A == a and i % B == b) { cout << i << endl; return 0; } } return 0; }