#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M; vector> v; //--------------------------------------------------------------------------------------------------- int get() { int d; cin >> d; string s; cin >> s; int h = (s[0] - '0') * 10 + s[1] - '0'; int m = (s[3] - '0') * 10 + s[4] - '0'; return d * 24 * 60 + h * 60 + m; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M; rep(i, 0, M) { int s = get(), t = get(); v.push_back({ t, s }); } sort(v.begin(), v.end()); priority_queue que; int ans = 0; fore(p, v) { int s = p.second; int t = p.first; while (!que.empty() && -que.top() < s) que.pop(); if (que.size() == N) continue; que.push(-t); ans++; } cout << ans << endl; }