#include using namespace std; const int MAXN = 100; const int MAXM = 1000; int N, M; int S[MAXM], T[MAXM]; int tord[MAXM]; signed main() { ios::sync_with_stdio(false); cin >> N >> M; for (int i = 0; i < M; ++i) { int d, h, m; char c; cin >> d >> h >> c >> m; S[i] = d * 24 * 60 + h * 60 + m; cin >> d >> h >> c >> m; T[i] = d * 24 * 60 + h * 60 + m + 1; tord[i] = i; } sort(tord, tord + M, [&] (int i, int j) { return T[i] < T[j]; }); multiset bag; for (int i = 0; i < N; ++i) { bag.emplace(-1); } int ans = 0; for (int i = 0; i < M; ++i) { auto it = bag.upper_bound(S[tord[i]]); if (it == bag.begin()) continue; ++ans; bag.erase(--it); bag.emplace(T[tord[i]]); } cout << ans << endl; return 0; }