import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, Chan;
    scan(N, Chan);
    auto S = new long[](N);
    auto T = new long[](N);
    auto C = new long[](N);
    foreach (i; 0 .. N)
        scan(S[i], T[i], C[i]);
    zip(C, S, T).sort();
    auto used = new long[][](30, 10 ^^ 5 + 2);
    foreach (i; 0 .. N)
    {
        if (i + 1 < N && C[i] == C[i + 1] && T[i] == S[i + 1])
        {
            S[i + 1] = S[i];
            continue;
        }
        used[C[i] - 1][S[i] - 1] = 1;
        used[C[i] - 1][T[i]] = -1;
    }
    foreach (i; 0 .. Chan)
        foreach (j; 0 .. 10 ^^ 5)
        {
            used[i][j + 1] += used[i][j];
        }
    long ans;
    foreach (i; 1 .. 10 ^^ 5 + 1)
    {
        long cnt1;
        foreach (j; 0 .. Chan)
            if (used[j][i] != 0)
                cnt1++;
        ans = ans.max(cnt1);
    }
    writeln(ans);
}
