import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; class Solution { public static void main(String[] args) { new Solution().run(); } class Edge implements Comparable { int src; int dst; public Edge(int src, int dst) { this.src = src; this.dst = dst; } @Override public int compareTo(Edge o) { return Integer.compare(src, o.src); } } void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[][] v = new int[m][2]; for (int i = 0; i < m; ++i) { int v1 = sc.nextInt(); String[] s1 = sc.next().split(":"); int v2 = sc.nextInt(); String[] s2 = sc.next().split(":"); int src = v1 * 10000 + new Integer(s1[0]) * 100 + new Integer(s1[1]); int dst = v2 * 10000 + new Integer(s2[0]) * 100 + new Integer(s2[1]); v[i][0] = src; v[i][1] = dst; } Arrays.sort(v, new Comparator() { @Override public int compare(int[] o1, int[] o2) { return Integer.compare(o1[0], o2[0]); } }); int ans = 0; int cnt = 0; ArrayList pending = new ArrayList<>(); for (int i = 0; i < m; ++i) { int src = v[i][0]; int dst = v[i][1]; pending.add(new Edge(v[i][0], v[i][1])); ++cnt; if (cnt <= n) { continue; } else { Edge tmp = null; for (int j = 0; j < pending.size(); ++j) { if (pending.get(j).dst < src) { pending.remove(j); --j; --cnt; ++ans; } if (j >= 0 && (tmp == null || tmp.dst < pending.get(j).dst)) { tmp = pending.get(j); } } if (cnt > n) { pending.remove(tmp); --cnt; if (cnt > n) throw new AssertionError(); } } } ans += cnt; System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }