#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n,c;cin>>n>>c;
    vp v[c];
    rep(i,n){
        int s,t,c_;
        cin >> s >> t >> c_;
        c_--;
        v[c_].push_back(P(s,t));
    }
    rep(i,c){
        sort(v[i].begin(),v[i].end());
    }

    int ans = 0;
    int flag[c] = {};
    int now[c] = {};

    rep(i,110000){
        int tmp = 0;
        rep(j,c){
            if(now[j]==v[j].size())continue;
            if(flag[j]==0){
                if(v[j][now[j]].first==i){
                    flag[j] = 1;
                    tmp++;
                }
            }else{
                tmp++;
                if(v[j][now[j]].second==i){
                    flag[j] = 0;
                    now[j]++;
                    if(now[j]!=v[j].size()){
                        if(v[j][now[j]].first==i){
                            flag[j] = 1;
                        }
                    }
                }
            }
        }
        ans = max(ans,tmp);
    }

    cout << ans << endl;
    return 0;
}
 
 
