import sequtils,algorithm,sugar proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0' or k > '9': break result = 10 * result + k.ord - '0'.ord proc parseLine(): tuple[x,y:int] = result.x = scan() * 1440 + scan() * 60 + scan() result.y = scan() * 1440 + scan() * 60 + scan() let n = scan() let m = scan() let U = newSeqWith(m,parseLine()).sortedByIt(it.y) var preY = newSeq[int](n) var ans = 0 for u in U: # preY は 小さい順に並んでいると過程 let i = preY.lowerBound(u.x) # それ以上の初のindex if i == 0: continue if preY[i-1] >= u.x : continue preY[i-1] = u.y ans += 1 preY.sort(cmp) echo ans