#include using namespace std; int main() { int A, B, a, b; cin >> A >> B >> a >> b; assert(1 <= A && A <= 3000); assert(1 <= B && B <= 3000); assert(0 <= a && a < A); assert(0 <= b && b < B); int val = 0; while (true) { if (val % A == a && val % B == b) break; val++; } cout << val << endl; }