while 1: a,b,m,n=map(int,raw_input().split()) while aa%n!=b:a+=m print-(a/m/n)or a