#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #ifndef ONLINE_JUDGE //#define _GLIBCXX_DEBUG #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long using ll = long long; using vll = vector; using vvll = vector; using vvvll = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vd = vector; using vc = vector; using vs = vector; using vb = vector; using vvb = vector; using pii = pair; using pcc = pair; using pll = pair; using pdd = pair; using vpii = vector; using vpll = vector; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repback(i, n) for (ll i = n-1; i >= 0; i--) #define REP(i, a, b) for (ll i = a; i < ll(b); i++) #define REPBACK(i, a, b) for (ll i = a-1; i >= ll(b); i--) #define all(x) (x).begin(), (x).end() #define pb push_back #define EPS (1e-10) #define equals(a,b) (fabs((a) - (b)) < EPS) #ifndef ONLINE_JUDGE #define debug(x) cout << "debug:" << (x) << endl #define debug2(x, y) cout << "debug:" << (x) << " " << (y) << endl #define debug3(x, y, z) cout << "debug:" << (x) << " " << (y) << " " << (z) << endl #define debug4(x, y, z, w) cout << "debug:" << (x) << " " << (y) << " " << (z) << (w) << endl #define debuga debug("a") #else #define debug(x) void(0) #define debug2(x, y) void(0) #define debug3(x, y, z) void(0) #define debug4(x, y, z, w) void(0) #define debuga void(0) #endif #define YESNO(bool) if(bool){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';} #define yesno(bool) if(bool){cout<<"yes"<<'\n';}else{cout<<"no"<<'\n';} #define YesNo(bool) if(bool){cout<<"Yes"<<'\n';}else{cout<<"No"<<'\n';} static const double pi = acos(-1.0); const long long INFL = pow(10,18); const long long INFLMAX = 9223372036854775807; const int INF = pow(10,9); const int INFMAX = 2147483647; const int mod1 = 1000000007; const int mod2 = 998244353; const vi dx1 = {1,0,-1,0}; const vi dy1 = {0,1,0,-1}; const vi dx2 = {0, 1, 1, 1, 0, -1, -1, -1, 0}; const vi dy2 = {1, 1, 0, -1, -1, -1, 0, 1, 1}; // vector出力 template ostream& operator << (ostream& os, vector& vec) { os << "["; for (int i = 0; i ostream& operator << (ostream& os, pair& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map出力 template ostream& operator << (ostream& os, map& map_var) { os << "{"; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set 出力 template ostream& operator << (ostream& os, set& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } class Point{ public: double x, y; Point(double x = 0, double y = 0): x(x), y(y) {} Point operator + (Point p) {return Point(x + p.x, y + p.y); } Point operator - (Point p) {return Point(x - p.x, y - p.y); } Point operator * (double a) {return Point(a * x, a * y); } Point operator / (double a) {return Point(x / a, y / a); } double norm() {return x * x + y * y; } double abs() {return sqrt(norm()); } bool operator == (const Point &p) const{ return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } bool operator < (const Point &p) const{ return x != p.x ? x < p.x : y < p.y; } }; double dot(Point a, Point b){return a.x * b.x + a.y * b.y;} double cross(Point a, Point b){return a.x * b.y - a.y * b.x;} struct Edge{ ll to, cost; Edge(ll to = 0, ll cost = 0) : to(to), cost(cost) {} }; using Graph = vector >; //x^n % mod を計算 ll mpow(ll x, ll n, ll mod){ x %= mod; ll ret = 1; while(n > 0){ if(n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } //10進数(long long) → 2進数(string)への変換 string toBinary(ll n) { if(n == 0) return "0"; string ret; while (n != 0){ ret += ( n % 2 == 0 ? '0' : '1' ); n /= 2; } reverse(ret.begin(), ret.end()); return ret; } //2進数(string) → 10進数(long long)への変換 ll toDecimal(string S){ ll ret = 0; for(int i = 0; i < S.size(); i++){ ret *= 2; if(S[i] == '1') ret += 1; } return ret; } ll gcd(ll a, ll b){ if(a < b) swap(a, b); if(a%b == 0) return b; else return gcd(b, a%b); } ll lcm(ll a, ll b){ return a*b / gcd(a, b); } //拡張ユークリッドの互除法 //ax + by = gcd(a, b) を満たす (x, y) が格納される (返り値: a と b の最大公約数) long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } // a = a/b * b + a % b を上式に再帰的に適用 long long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } // 行列同士の積 vvll matrix_prod(vvll &A, vvll &B){ // Aは i * k , Bは k * j の行列 -> 積で i * j の行列を返す assert(A[0].size() == B.size()); int r = A.size(); int c = B[0].size(); vvll ret(r, vll(c,0)); rep(i,r){ rep(j,c){ rep(k,B.size()){ ret[i][j] += A[i][k] * B[k][j]; } } } return ret; } //Union-Find struct unionfind{ vector par, siz; //初期化 unionfind(int n) : par(n, -1), siz(n, 1) {} //根を求める int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } //xとyの根(グループ)が一致するかどうか bool issame(int x, int y){ return root(x) == root(y); } //xとyのグループの併合 bool unite(int x, int y){ x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x,y); par[y] = x; siz[x] += siz[y]; return true; } //xを含むグループのサイズ int size(int x){ return siz[root(x)]; } }; signed main(){ cin.tie(0); ios_base::sync_with_stdio(false); //cout << fixed << setprecision(10); int n,m; cin >> n >> m; vpii es(m); rep(i,m){ int time = 0; int d; cin >> d; time += 24 * 60 * d; rep(i,5){ char c; cin >> c; if(i == 2) continue; else if(i == 0) time += 10*60*(c-'0'); else if(i == 1) time += 60 * (c-'0'); else if(i == 3) time += 10 * (c - '0'); else time += (c - '0'); } es[i].second = time; time = 0; cin >> d; time += 24 * 60 * d; rep(i,5){ char c; cin >> c; if(i == 2) continue; else if(i == 0) time += 10*60*(c-'0'); else if(i == 1) time += 60 * (c-'0'); else if(i == 3) time += 10 * (c - '0'); else time += (c - '0'); } es[i].first = time; } sort(all(es)); multiset st; rep(i,n) st.insert(-1); int ans = 0; rep(i,m){ int nowstart = es[i].second; auto it = st.upper_bound(nowstart-1); if(it == st.begin()) continue; it--; ans++; st.erase(it); st.insert(es[i].first); } cout << ans << endl; }