from collections import defaultdict A,B,a,b=map(int,input().split()) d=defaultdict(int) for i in range(a, 3000, A ): d[i] += 1 for i in range(b, 3000, B ): d[i] += 1 ans=999999 for k in d: ans=min(ans, k if d[k] ==2 else 999999) print(ans)