#include "bits/stdc++.h"
using namespace std;
const int maxn = 300300;
int s[maxn], t[maxn], cc[maxn];
int xx[maxn];
int main(){
    int n, c;
    scanf("%d %d", &n, &c);
    for(int e = 0; e < n; e++){
        scanf("%d %d %d", s + e, t + e, cc + e);
        s[e] *= 2; s[e] += 1;
        t[e] *= 2; t[e] += 1;
        xx[s[e]] |= 1<<cc[e];
        xx[t[e]+1] |= 1<<cc[e];
    }
    for(int e = 1; e < maxn; e++) xx[e] ^= xx[e-1];
    int nd = 0;
    for(int e = 0; e < maxn; e++){
        nd = max(nd, __builtin_popcount(xx[e]));
    }
    cout << nd << endl;
    return 0;
}
