#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter from bisect import bisect_left # %% N, M = map(int, readline().split()) lines = readlines() # %% LR = [] for line in lines: day1, hm1, day2, hm2 = line.split() h1, m1 = hm1.split(b':') h2, m2 = hm2.split(b':') L = int(day1) * 1440 + int(h1) * 60 + int(m1) R = int(day2) * 1440 + int(h2) * 60 + int(m2) LR.append((L, R)) LR.sort(key=itemgetter(1)) # %% answer = 0 end_times = [] for L, R in LR: i = bisect_left(end_times, L) if i: del end_times[i - 1] end_times.append(R) answer += 1 elif len(end_times) < N: end_times.append(R) answer += 1 continue # %% print(answer) # %%