#include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; #define rep(i,n) for(ll i=0;i<(n);i++) #define pii pair #define piii pair #define mp make_pair #define pb push_back #define ALL(a) (a).begin(),(a).end() #define FST first #define SEC second const int INF = (INT_MAX/2); const ll LLINF = (LLONG_MAX/2); const double eps = 1e-5; const double PI = M_PI; #define DEB cerr<<"!"< tii; vector x(100001); int main(){ int n,m; cin >> n >> m; vector a; vector b; rep(i,n){ int xx,aa,bb; cin >> xx >> aa >> bb; a.pb(tii{i,aa}); b.pb(tii{i,bb}); x[i] = xx+1; } sort(ALL(a),[](tii a,tii b){return get<1>(a) < get<1>(b);}); sort(ALL(b),[](tii a,tii b){return get<1>(a) < get<1>(b);}); int ans = INF; int now_a = -1, now_b = 100001; int a_index = 0, b_index = n-1; int cnt[6] = {}; rep(i,n){cnt[x[i]]++;} while(now_a < 100001 && now_b >= -1){ // SHOW(now_a,now_b); // rep(i,6)cerr <<" "<= m){ ans = min(ans,cnt[3]+cnt[4]+cnt[5]); now_a++; for(;a_index < n && get<1>(a[a_index]) < now_a; a_index++){ cnt[x[get<0>(a[a_index])]]--; x[get<0>(a[a_index])]--; cnt[x[get<0>(a[a_index])]]++; } }else{ now_b--; for(;b_index >= 0 && get<1>(b[b_index]) > now_b; b_index--){ cnt[x[get<0>(b[b_index])]]--; x[get<0>(b[b_index])]++; cnt[x[get<0>(b[b_index])]]++; } } } cout << ans << endl; }