## https://yukicoder.me/problems/no/580 def main(): N, M = map(int, input().split()) lists = [] for _ in range(M): d, hhmmd, o, hhommo = input().split() d = int(d) hhd, mmd = map(int, hhmmd.split(":")) o = int(o) hho, mmo = map(int, hhommo.split(":")) s = (d -2 ) * (60 * 24) + hhd * 60 + mmd g = (o -2 ) * (60 * 24) + hho * 60 + mmo lists.append((s, g)) lists.sort(key=lambda x : x[1] * 1000000 + x[0]) room_ends = [-2] * N answer = 0 for s, g in lists: target_s = -float("inf") target_n = -1 for n in range(N): if room_ends[n] < s: if room_ends[n] > target_s: target_s = room_ends[n] target_n = n if target_n != -1: room_ends[target_n] = g answer += 1 print(answer) if __name__ == '__main__': main()