#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; bool cmp(pii a, pii b) { if (a.second != b.second) { return a.second < b.second; } else { return a.first > b.first; } } int main(){ int N, M; cin >> N >> M; vi in(M), out(M); vector reserve(M); vi times; rep(i, M) { int in_d, in_h, in_m, out_d, out_h, out_m; scanf("%d %d:%d", &in_d, &in_h, &in_m); scanf("%d %d:%d", &out_d, &out_h, &out_m); in[i] = in_m + 60 * (in_h + 24 * in_d); out[i] = out_m + 60 * (out_h + 24 * out_d); reserve[i] = mp(in[i], out[i]); times.push_back(in[i]); times.push_back(out[i]); } sort(all(times)); times.erase(unique(all(times)), times.end()); sort(all(reserve), cmp); int T = sz(times); auto lb = [&](int x) { return lower_bound(all(times), x) - times.begin(); }; vi cnt(T); int ans = 0; each(re, reserve) { int l = lb(re.first), r = lb(re.second); int ma = 0; for (int i = l; i <= r; ++i)smax(ma, cnt[i]); if (ma < N) { ans++; for (int i = l; i <= r; ++i)cnt[i]++; } } cout << ans << endl; }