import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Seg = Tuple!(int, "s", int, "t");

void main() {
    int n, c;
    scan(n, c);

    auto cs = new Seg[][](c, 0);

    foreach (i ; 0 .. n) {
        int si, ti, ci;
        scan(si, ti, ci);
        cs[ci-1] ~= Seg(si, ti);
    }

    foreach (i ; 0 .. c) {
        cs[i].sort();
    }

    auto ims = new int[](2 * 10^^5 + 1);

    foreach (i ; 0 .. c) {
        if (cs[i].empty) continue;
        ims[cs[i][0].s]++;
        ims[cs[i][0].t + 1]--;

        foreach (j ; 1 .. cs[i].length) {
            if (cs[i][j].s == cs[i][j-1].t) {
                ims[cs[i][j].s + 1]++;
                ims[cs[i][j].t + 1]--;
            }
            else {
                ims[cs[i][j].s]++;
                ims[cs[i][j].t + 1]--;
            }
        }
    }

    foreach (i ; 1 .. 2*10^^5) {
        ims[i] += ims[i-1];
    }

    debug {
        writeln(ims[0 .. 20]);
    }

    int ans = ims.reduce!max;

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}