#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;

int main(){
    ll n, k; cin >> n >> k;
    VI a(n), b(n), c(n);
    REP(i,n) cin >> a[i] >> b[i] >> c[i], b[i]++;
    set<int> t;
    REP(i,n){
        t.insert(a[i]);
        t.insert(b[i]);
    }
    map<int,int> mp;
    int tm=0;
    VI tt;
    for(auto x:t) tt.push_back(x);
    REP(i,tt.size()){
        mp[tt[i]]=tm;
        tm++;
    }
    VI im(tt.size(),0);
    REP(i,n){
        im[mp[a[i]]]+=c[i];
        im[mp[b[i]]]-=c[i];
    }
    ll ans=0, now=0;
    REP(i,tt.size()-1){
        now+=im[i];
        if(k<now)
            ans+=(tt[i+1]-tt[i])*k;
        else
            ans+=(tt[i+1]-tt[i])*now;
    }
    cout << ans << endl;
    return 0;
}
#include"bits/stdc++.h"
using namespace std;

#define int long long
#define pb push_back
#define all(v) begin(v), end(v)
#define sz(v) (int)v.size()
#define ff first
#define ss second
const int inf = 4e18;
const int N = 2e5 + 10;

int n, m;
int dp[1 << 20];
vector<pair<int, int>> q[20];

int rec(int pos, int mask) {
	int &ans = dp[mask];
	if (pos == n) return 1;
	if (ans != -1) return ans;

	ans = 0;
	for (int i = 0; i < n; i++) {
		if (!(mask & (1 << i))) {
			int nMask = mask | (1 << i);
			bool can = 1;
			for (auto &p : q[pos]) {
				int got = ((1 << p.ff) - 1) & nMask;
				can &= (__builtin_popcountll(got) <= p.ss);
			}

			if (can) ans += rec(pos + 1, nMask);
		}
	}

	return ans;
}

void testCase() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y, z; cin >> x >> y >> z; x--;
		q[x].pb({y, z});
	}

	memset(dp, -1, sizeof(dp));
	cout << rec(0, 0);
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--) testCase();
}