n, M, P, Q = gets.split.map(&:to_i) month = 1 month_count = 0 loop do month_count += 1 n -= M if P + Q > 12 n -= M if month.between?(P, 12) || month.between?(1, (P + Q - 1) % 12) elsif month.between?(P, P + Q - 1) n -= M end break if n <= 0 month += 1 month = 1 if month > 12 end puts month_count