#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); rep(i, M) { int in_d, in_h, in_m, out_d, out_h, out_m; char hoge; cin >> in_d >> in_h >> hoge >> in_m; cin >> out_d >> out_h >> hoge >> 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]); } sort(all(reserve), cmp); vi cnt(20000); int ans = 0; each(re, reserve) { int l, r, ma = 0; tie(l, r) = re; 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; }