#include using namespace std; using Pi = pair; int main() { int n, m; int t[1001][2]; scanf("%d %d", &n, &m); for(int i = 0; i < m; i++) { for(int j = 0; j < 2; j++) { int d, h, m; scanf("%d %d:%d", &d, &h, &m); t[i][j] = d*24*60+h*60+m; } } vector vec; for(int i = 0; i < m; i++) { vec.emplace_back(t[i][0], t[i][1]); } sort(vec.begin(), vec.end()); int room[101] = {}; vector who; int ans = 0; auto print = [&](int ts) { printf("%d %d:%d\n", ts/(24*60), ts%(24*60)/60, ts%(24*60)%60); }; function dfs = [&](int idx, int cnt) { if(idx == m) { ans = max(ans, cnt); /* if(cnt == 11) { for(int s : who) { print(s); } exit(0); } */ return; } dfs(idx+1, cnt); for(int i = 0; i < n; i++) { if(room[i] < vec[idx].first) { int tmp = room[i]; room[i] = vec[idx].second; who.push_back(vec[idx].second); dfs(idx+1, cnt+1); who.pop_back(); room[i] = tmp; } } }; dfs(0, 0); printf("%d\n", ans); return 0; }