#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector > ts(m); for (int i = 0; i < m; i++) { int d1, h1, m1, d2, h2, m2; char _; cin >> d1 >> h1 >> _ >> m1 >> d2 >> h2 >> _ >> m2; int in = 60 * (24 * d1 + h1) + m1; int out = 60 * (24 * d2 + h2) + m2; ts[i] = make_pair(out, in); } sort(ts.begin(), ts.end()); int ret = 0; queue q; for (int i = 0; i < m; i++) { int in, out; tie(out, in) = ts[i]; while (!q.empty() && q.front() < in) { q.pop(); } if (q.size() < n) { ++ret; q.push(ts[i].first); } } cout << ret << endl; return 0; }