package main import ( "bufio" "fmt" "os" "sort" "strconv" "strings" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) m := getNextInt(scanner) mm := make([]pair, m) for i := 0; i < m; i++ { mm[i][0] = datetominites(getNextInt(scanner), getNextString(scanner)) mm[i][1] = datetominites(getNextInt(scanner), getNextString(scanner)) } sort.Slice(mm, func(i, j int) bool { return mm[i][1] < mm[j][1] }) var ans int q := make([]int, 0) for i := 0; i < m; i++ { for len(q) > 0 && q[0] < mm[i][0] { q = q[1:] } if len(q) < n { q = append(q, mm[i][1]) ans++ } } fmt.Fprintln(writer, ans) } func datetominites(d int, s string) int { hm := strings.Split(s, ":") return d*24*60 + strtoint(hm[0])*24 + strtoint(hm[1]) } func strtoint(s string) int { return int(s[0]-'0')*10 + int(s[1]-'0') } type pair [2]int