n, m, p, q = map(int, input().split()) leaf = 0 i = 1 while leaf < n: check = i % 12 if p <= check <= p + q - 1: leaf += m * 2 elif i % 12 == 0 and p + q - 1 == 12: leaf += m * 2 else: leaf += m if leaf == n: break i += 1 print(i)