#[allow(unused_macros)]
macro_rules! debug {
  ($($e:expr), *) => {println!(concat!($(stringify!($e), " = {:?}\n"), *), $($e), *)}
}

fn main() {
  let (n, _) = get::tuple::<usize,usize>();
  let mut stc = get::tuple3s::<usize,usize,usize>(n);
  
  let unite = |p: &Vec<(usize,usize,usize)>| {
    let &(s1,_,c1) = p.first().unwrap();
    let &(_,t2,_) = p.last().unwrap();
    (s1, t2, c1)
  };
    
  stc.sort_by(|&(s1,_,c1),&(s2,_,c2)|(c1,s1).cmp(&(c2,s2)));
  let stc_grouped = group_by(&stc, |&(_,t1,c1),&(s2,_,c2)|t1==s2&&c1==c2);
  let stc_norm = stc_grouped.iter().map(unite).collect::<Vec<_>>(); //debug!(stc_norm); 
  
  let mut imos = vec![0isize; 100002];
  let mut max = 0;
  for (s,t,_) in stc_norm {
    imos[s] += 1;
    imos[t+1] -= 1
  }
  for i in 1 .. imos.len() {
    imos[i] = imos[i-1] + imos[i];
    max = std::cmp::max(max, imos[i])
  }
  //debug!(imos);
  println!("{}", max)
}

fn group_by<T: PartialEq + Clone, F>(vec: &Vec<T>, f: F) -> Vec<Vec<T>> where F: Fn(&T, &T) -> bool {
  let l = vec.len();
  let mut gs = vec![];
  let mut g = vec![];
  for i in 0 .. l {
    g.push(vec[i].clone());
    if i < l-1 && !f(&vec[i], &vec[i+1]) {
      gs.push(g.clone());
      g.clear()
    }
  }
  gs.push(g.clone());
  gs
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}



Measured memory_bytes: 20728