// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int gg = 0 ;
vector <pair<int,int>> G[200000];
// Function to sort the vector elements
// by second element of pairs
bool sortbysec(const pair<int, int>& a,
const pair<int, int>& b)
{
return (a.second < b.second);
}
// Function to find maximal disjoint set
void maxDisjointIntervals(vector<pair<int, int> > list)
{
// Sort the list of intervals
sort(list.begin(), list.end(), sortbysec);
// First Interval will always be
// included in set
// cout << "[" << list[0].first << ", "
// << list[0].second << "]" << endl;
gg++;
// End point of first interval
int r1 = list[0].second;
for (int i = 1; i < list.size(); i++) {
int l1 = list[i].first;
int r2 = list[i].second;
// Check if given interval overlap with
// previously included interval, if not
// then include this interval and update
// the end point of last added interval
if (l1 > r1) {
// cout << "[" << l1 << ", "
// << r2 << "]" << endl;
gg++;
r1 = r2;
}
}
}
// Driver code
int main()
{
int N = 4;
// vector<pair<int, int> > intervals = { { 1, 4 },
// { 2, 4 },
// { 4, 6 },
// { 8, 9 } };
int n,k;
cin>>n>>k ;
int i = 0 ;
while(i<n){
int x,y,t;
cin>>x>>y>>t ;
G[t].push_back({x,y-1});
i++;
}
i = 0 ;
while(i<=100){
vector<pair<int, int> > intervals ;
int j = 0 ; int p = G[i].size();
while(j<p){
pair<int,int> yy = G[i][j];
intervals.push_back(yy);
j++;
}
// maxDisjointIntervals(intervals);
int vv = intervals.size();
//cout<<vv<<"\n";
if(vv>=1){
maxDisjointIntervals(intervals);
}
i++;
}
cout<<gg ;
return 0;
}