import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); PriorityQueue queue = new PriorityQueue<>(); for (int i = 0; i < m; i++) { queue.add(new Reserve(i, sc.nextInt(), sc.next(), sc.nextInt(), sc.next())); } int outBound = 0; TreeSet remains = new TreeSet<>(); while (queue.size() > 0) { Reserve r = queue.poll(); while (remains.size() > 0 && remains.first().time < r.start) { remains.remove(remains.pollFirst()); } remains.add(new Remain(r)); while (remains.size() > n) { remains.pollLast(); outBound++; } } System.out.println(m - outBound); } static class Remain implements Comparable { int idx; int time; public Remain(int idx, int time) { this.idx = idx; this.time = time; } public Remain(Reserve r) { this(r.idx, r.end); } public int hashCode() { return idx; } public int compareTo(Remain another) { if (time == another.time) { return idx - another.idx; } else { return time - another.time; } } public boolean equals(Object o) { Remain r = (Remain) o; return idx == r.idx; } } static class Reserve implements Comparable { int idx; int start; int end; public Reserve(int idx, int start, int end) { this.idx = idx; this.start = start; this.end = end; } public Reserve(int idx, int startDay, String startTime, int endDay, String endTime) { this(idx, getMinute(startDay, startTime), getMinute(endDay, endTime)); } static int getMinute(int day, String time) { return (day - 2) * 24 * 60 + timeToMinute(time); } static int timeToMinute(String time) { String[] arr = time.split(":", 2); return Integer.parseInt(arr[0]) * 60 + Integer.parseInt(arr[1]); } public int compareTo(Reserve another) { return start - another.start; } } }