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