// Slower C++ solution:
/* ---------- STL Libraries ---------- */

// IO library

#include <cstdio>

#include <fstream>

#include <iomanip>

#include <ios>

#include <iostream>



// algorithm library

#include <algorithm>

#include <cmath>

#include <numeric>

#include <random>



// container library

#include <array>

#include <bitset>

#include <deque>

#include <map>

#include <queue>

#include <set>

#include <string>

#include <tuple>

#include <vector>



/* ---------- Namespace ---------- */

using namespace std;



/* ---------- Type Abbreviation ---------- */

using ll = long long;



/* ---------- Constants  */

const ll MOD = 1e9 + 7;

// const int INF = 1 << 25;

// const ll INF = 1LL << 50;

// const double PI = acos(-1);

// const double EPS = 1e-10;

// mt19937 mert(LL(time(0)));



/* ---------- Short Functions ---------- */

template <typename T>

T gcd(T a, T b) {

    if (a > b) return gcd(b, a);

    return a == 0 ? b : gcd(b % a, a);

}



template <typename T, typename U>

T mypow(T b, U n) {

    if (n == 0) return 1;

    if (n == 1) return b /* % MOD */;

    if (n % 2 == 0) {

        return mypow(b * b /* % MOD */, n / 2);

    } else {

        return mypow(b, n - 1) * b /* % MOD */;

    }

}



/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */



int main() {

    int N, c;

    cin >> N >> c;



    int time = (int) pow(10, 5) + 1;



    int table[time][c];

    fill(table[0], table[time], 0);



    for (int i = 0; i < N; i++) {

        int s, t, c;

        cin >> s >> t >> c;

        c--;



        table[s][c]++;

        table[t][c]--;

    }



    for (int i = 1; i < time; i++) {

        for (int j = 0; j < c; j++) {

            table[i][j] += table[i-1][j];

        }

    }



    for (int i = 1; i < time; i++) {

        for (int j = 0; j < c; j++) {

            if (table[i][j] != 0 && table[i-1][j] == 0) table[i-1][j] = 1;

        }

    }



    int ret = -1;

    for (int i = 0; i < time; i++) {

        int cnt = 0;



        for (int j = 0; j < c; j++) {

            cnt += table[i][j];

        }



        ret = max(ret, cnt);

    }



    cout << ret << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.72846042475363x):
/* ---------- STL Libraries ---------- */

// IO library

#include <cstdio>

#include <fstream>

#include <iomanip>

#include <ios>

#include <iostream>



// algorithm library

#include <algorithm>

#include <cmath>

#include <numeric>

#include <random>



// container library

#include <array>

#include <bitset>

#include <deque>

#include <map>

#include <unordered_map>

#include <queue>

#include <set>

#include <string>

#include <tuple>

#include <vector>



/* ---------- Namespace ---------- */

using namespace std;



/* ---------- Type ---------- */

using ll = long long;

#define int ll

#define P pair<ll, ll>



/* ---------- Constants  */

const double PI = 3.141592653589793238462643383279;

const ll MOD = 1e9 + 7;

const int INF = 1LL << 55;



/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int const MAX_T = 100000;



signed main() {

    int N, C;

    cin >> N >> C;



    bool table[C][MAX_T];

    fill(table[0], table[C], false);



    for (int i = 0; i < N; i++) {

        int s, t, c;

        cin >> s >> t >> c;

        s--; t--; c--;



        for (int time = s; time < t; time++) {

            table[c][time] = true;

        }

    }



    for (int ch = 0; ch < C; ch++) {

        bool flag = false;

        for (int time = MAX_T - 1; time >= 0; time--) {

            if (table[ch][time]) {

                flag = true;

            } else {

                if (flag) {

                    table[ch][time] = true;

                    flag = false;

                }

            }

        }

    }



    int ret = -1;

    for (int time = 0; time < MAX_T; time++) {

        int cnt = 0;

        for (int ch = 0; ch < C; ch++) {

            if (table[ch][time]) cnt++;

        }



        ret = max(ret, cnt);

    }



    cout << ret << endl;



    return 0;

}