#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(); } //--------------------------------------------------------------------------------------------------- template class HogloidHeap { private: std::size_t sz; std::priority_queue g, gd; std::priority_queue, std::greater > l, ld; void flush_min() { while (!ld.empty() && l.top() == ld.top()) { l.pop(); ld.pop(); } } void flush_max() { while (!gd.empty() && g.top() == gd.top()) { g.pop(); gd.pop(); } } public: HogloidHeap() : sz(0) {} bool empty() const { return size() == 0; } std::size_t size() const { return sz; } const T &min() { flush_min(); return l.top(); } const T &max() { flush_max(); return g.top(); } void push(const T &v) { l.push(v); g.push(v); ++sz; } template void emplace(Args &&... args) { l.emplace(std::forward(args)...); g.emplace(std::forward(args)...); ++sz; } void pop_min() { flush_min(); gd.emplace(l.top()); l.pop(); --sz; } void pop_max() { flush_max(); ld.emplace(g.top()); g.pop(); --sz; } }; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  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({ s, t }); } sort(v.begin(), v.end()); HogloidHeap que; int ans = 0; fore(p, v) { int s = p.first; int t = p.second; while (!que.empty() && que.min() < s) que.pop_min(); if (que.size() == N) { if (t < que.max()) { que.pop_max(); que.push(t); } continue; } que.push(t); ans++; } cout << ans << endl; }