#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout << #x << ": " << x << endl; #define DEBUG_VEC(v) cout << #v << ":";for (int i = 0; i < v.size(); i++) cout << " " << v[i];cout << endl; typedef long long ll; #define vi vector #define vl vector #define vii vector > #define vll vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 1e18 * 4; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout << setprecision(15) << fixed << p << endl; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int main(){ int n, V, i, j; scanf("%d%d",&n, &V); vector a(V); for (i = 0; i < V; i++) { int d,hh,mm,o,hho,mmo; scanf("%d %d:%d %d %d:%d",&d,&hh,&mm,&o,&hho,&mmo); int s, g; s = (d - 2)*24*60 + hh*60 + mm; g = (o - 2)*24*60 + hho*60 + mmo; a[i] = pii(s, g); } sort(a.begin(), a.end()); int cnt = 0; int ans = 0; vector f(n); /* for (j = 0; j < V; j++) { printf("(%d, %d)\n", a[j].first, a[j].second); } */ for (i = 0; i < V; i++) { for (j = 0; j < cnt; j++) { if (a[i].first > f[j].second) { ans++; f[j] = a[i]; break; } } if (j == cnt) { if (cnt < n) { f[cnt++] = a[i]; } else { int slow = -1, slowi = -1; for (j = 0; j < cnt; j++) { if (slow < f[j].second) { slow = f[j].second; slowi = j; } } if (slow > a[i].second) { f[slowi] = a[i]; } } } /* DEBUG(ans); for (j = 0; j < cnt; j++) { printf("(%d, %d) ", f[j].first, f[j].second); } cout << endl; */ } cout<< ans + cnt <