N, M, P, Q = map(int, input().split()) i = 1 while N > 0: m = i - (i -1) // 12 * 12 if P <= m < P + Q: N -= M * 2 else: N -= M i += 1 print(i - 1)