# 中国剰余定理 # [0,AxB)の範囲を全検索すればよい A,B,a,b = map(int, input().split()) for x in range(A*B): if x % A == a and x % B == b: print(x) exit()