a,b,c,d = map(int, input().split()) for i in range(3001): for j in range(3001): if a*i+c==b*j+d: print(a*i+c) exit()