n, m, p, q = map(int, input().split()) for i in range(1, n+1): j = i i %= 12 if i == 0: i = 12 if p <= i <= p+q-1: n -= 2*m else: n -= m if n <= 0: print(j) exit()