n,m,p,q=map(int,input().split()) b=0 for i in range(1,13): b+=m if p<=i<=p+q-1:b+=m if n%((12+q)*m)<=b:break print(n//((12+q)*m)*12+i)