using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public int N, M; public Data[] D; public int[] R; public void Run() { // Input { var line = Input.ReadIntArray(); N = line[0]; M = line[1]; } D = new Data[M]; for (int i = 0; i < M; i++) { var line = Console.ReadLine(); D[i] = new Data(line); } // Sort Array.Sort(D, (d1, d2) => (d1.O.CompareTo(d2.O))); // Set Rooms R = new int[N]; for (int i = 0; i < N; i++) R[i] = -1; // Solve int ret = 0; for (int i = 0; i < M; i++) { int last_room = -1; int last_t = -2; for (int j = 0; j < N; j++) { // チェックイン時刻には空いており、かつ条件を満たす者の中で最も遅い if (R[j] < D[i].I && R[j] > last_t) { last_room = j; last_t = R[j]; } } if (last_room != -1) { R[last_room] = D[i].O; ret++; } } Console.WriteLine(ret); } } // libs ---------- class Data { public int I, O; public Data(string line) { int ID = int.Parse(line.Substring(0, 1)); int IH = int.Parse(line.Substring(2, 2)); int IM = int.Parse(line.Substring(5, 2)); int OD = int.Parse(line.Substring(8, 2)); int OH = int.Parse(line.Substring(10, 2)); int OM = int.Parse(line.Substring(13, 2)); I = ID * 24 * 60 + IH * 60 + IM; O = OD * 24 * 60 + OH * 60 + OM; } } // common ---------- internal static class Input { public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }