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