#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define getBit(x,i) (x&(1<<i))
#define setBit(x,i) (x|(1<<i))
#define mem(A,N) memset(A,N,sizeof(A))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define rep(i, x, y)  for(int i = x; i < y; ++i)
#define Rep(i, x, y)  for(int i = x; i <= y; ++i)
#define srep(i, x, y) for(int i = x; i > y; --i)
#define sRep(i, x, y) for(int i = x; i >= y; --i)
#define all(v) v.begin(),v.end()
#define Sort(x) sort(x.begin(), x.end())
#define f1(i,n) for (int i=1; i<=n; i++)
#define f0(i,n) for (int i=0; i<n; i++)
#define sz(x) ((int)(x).size())
#define len(x) ((int)(x).length())
#define fi first
#define se second

#define linf 0x7FFFFFFFFFFFFFFF
#define inf 0x7FFFFFFF
#define mod 1000000007
#define eps 1e-9
#define Pi 3.14159265358979323846

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define write(x) cerr << #x << " = " << (x) << ", "
#define writeI0 cerr << "i = " << 0 << ", "
#define dumpI0 cerr << "i = " << 0 << endl
#define printSet(x) for(auto it = s.begin(); it!=s.end(); it++) (it==s.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printVector(x) for(auto it = x.begin(); it!=x.end(); it++) (it==x.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printArray(a,x,y) for(auto it = a+x; it != a+y; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;
#define PrintArray(a,x,y) for(auto it = a+x; it != a+y+1; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;

// ***************** End Of Template ********************

#define maxSegm 262143

int segm_tree[262143];
int lazy[262143];

void propagate(int node, int left, int right) {
    segm_tree[node] |= lazy[node];
    if (left < right) {
        lazy[2 * node + 1] |= lazy[node];
        lazy[2 * node + 2] |= lazy[node];
    }
    lazy[node] = 0;
}

void update(int node, int left, int right, int x, int y, int v) {
    propagate(node, left, right);
    if (x <= left && right <= y) {
        lazy[node] |= v;
    } else {
        int middle = (left + right) / 2;
        if (x <= middle) {
            update(2 * node + 1, left, middle, x, y, v);
        }
        if (y >= middle + 1) {
            update(2 * node + 2, middle + 1, right, x, y, v);
        }
        propagate(2 * node + 1, left, middle);
        propagate(2 * node + 2, middle + 1, right);
        segm_tree[node] = segm_tree[2 * node + 1] | segm_tree[2 * node + 2];
    }
}

int query(int node, int left, int right, int x, int y) {
    propagate(node, left, right);
    if (x <= left && right <= y) {
        return segm_tree[node];
    } else {
        int middle = (left + right) / 2;
        if (x <= middle) {
            if (y >= middle + 1) {
                return max(query(2 * node + 1, left, middle, x, y), query(2 * node + 2, middle + 1, right, x, y));
            }
            else {
                return query(2 * node + 1, left, middle, x, y);
            }
        }
        else {
            return query(2 * node + 2, middle + 1, right, x, y);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, c, t1, t2, t3; cin >> n >> c;
    int mn = 1e9, mx = -1e9;
    while(n--) {
        cin >> t1 >> t2 >> t3;
        t1--; t2--;
        mn = min(mn, t1);
        mx = max(mx, t2);
        update(0, 0, 99999, t1, t2, (1<<(t3-1)));
    }
    int mx2 = 0;
    Rep(i, mn, mx) {
        mx2 = max(mx2, __builtin_popcount(query(0, 0, 99999, i, i)));
    }
    cout << mx2;
    return 0;
}


Measured memory_bytes: 2304