N,M,P,Q=map(int,input().split()) for i in range(N): temp=i%12 if temp>=P-1 and temp<=P+Q-2: N-=2*M else: N-=M if N<=0: print(i+1) break