A,B,a,b=map(int,input().split()) for x in range(a,10**9,A): if x%B==b: print(x) break