local n, c = io.read("*n", "*n")
local tbl = {}
for i = 1, n do
  local tmp = {}
  tmp.s, tmp.t, tmp.c = io.read("*n", "*n", "*n")
  tbl[i] = tmp
end
table.sort(tbl, function(a, b) return a.s < b.s end)
local rec_end = {tbl[1].t}
local rec_ch = {tbl[1].c}

for i = 2, n do
  local fpos = nil
  for ir = 1, #rec_end do
    if rec_end[ir] == tbl[i].s and rec_ch[ir] == tbl[i].c then
      rec_end[ir] = tbl[i].t
      fpos = ir
      break
    elseif rec_end[ir] < tbl[i].s then
      if not fpos then
        fpos = ir
      else
        if rec_end[ir] < rec_end[fpos] then
          fpos = ir
        end
      end
    end
  end
  if fpos then
    rec_end[fpos] = tbl[i].t
    rec_ch[fpos] = tbl[i].c
  else
    table.insert(rec_end, tbl[i].t)
    table.insert(rec_ch, tbl[i].c)
  end
end
print(#rec_end)
