n,m = map(int,input().split()) hotel = [[0,0,0]for i in range(n)] yoyaku = [] for i in range(m): y = input().split() yoyaku.append(list(map(int,[y[2]]+y[3].split(":")+[y[0]]+y[1].split(":")))) yoyaku.sort() cnt=0 for i in range(m): for j in range(n): if yoyaku[i][3:]>hotel[j]: hotel[j]=yoyaku[j][:3] cnt+=1 break print(cnt)