#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; struct Reservation { int start; int end; bool operator<(const Reservation& r) const { // return start < r.start; return end < r.end; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; constexpr int DAY = 1440; constexpr int HOUR = 60; vector res; for (int i = 0; i < m; i++) { int d; cin >> d; string s1; cin >> s1; const int start = d * DAY + stoi(s1.substr(0, 2)) * HOUR + stoi(s1.substr(3, 2)); int o; cin >> o; string s2; cin >> s2; const int end = o * DAY + stoi(s2.substr(0, 2)) * HOUR + stoi(s2.substr(3, 2)) + 1; res.push_back(Reservation{start, end}); } sort(res.begin(), res.end()); // show(res); vector used(m, false); vector end(n, 0); for (int i = 0; i < m; i++) { if ((not used[i])) { int maxj = -1; int maxi = 0; for (int j = 0; j < n; j++) { if (end[j] <= res[i].start) { if (maxi <= end[j]) { maxi = end[j]; maxj = j; } } } if (maxj != -1) { used[i] = true; end[maxj] = res[i].end; } } } cerr << endl; int num = 0; for (int i = 0; i < m; i++) { if (used[i]) { num++; } } cout << num << endl; }