A,B,a,b=map(int,input().split()) i=a while i%B!=b:i+=A print(i)