#include using namespace std; int main() { //cinX script int A; int B; int a; int b; cin >> A >> B >> a >> b; int N; N = 0; while (N % A == a && N % B == b) { N++; } cout << N << endl; }