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