#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, C;
    cin >> n >> C;

    vector<pair<ll, ll>> event;

    rep(i, n) {
        ll a, b, c;
        cin >> a >> b >> c;
        event.pb({a, c});
        event.pb({b + 1, -c});
    }
    sort(event.begin(), event.end());

    ll res = 0, t = 0, fee = 0;
    for (auto v : event) {
        if (v.first != t) {
            res += min(C, fee) * (v.first - t);
            t = v.first;
        }
        fee += v.second;
    }

    cout << res << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define d(x) cout<<x<<" "
#define nl cout<<endl
#define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var)
#define tt ll t;cin>>t;while(t--)
#define show(a,b) rep(i,0,b) d(a[i]);nl;
#define mod 1000000007
#define vi vector<int>
#define pii pair<int,int>
const int d4i[] = {-1,0,1,0};
const int d4j[] = {0,1,0,-1};

const int d8i[] = {-1,-1,-1,0,1,1,1,0};
const int d8j[] = {-1,0,1,1,1,0,-1,-1};
// #define ONLINE_JUDGE true

int ti[8][8];
int n,k;

int cal_time(vi val){
	int tii = 0;
	rep(i,0,n){
		int a = val[i]-1;
		int b = val[i+1]-1;
		tii+=ti[a][b];
		if(b==0) return tii;
	}
	return tii;
}

void solve(){
	cin>>n>>k;

	rep(i,0,n){
		rep(j,0,n) cin>>ti[i][j];
	}
	vector<int> ans;
	ans.pb(1);
	rep(i,1,n+1) ans.pb(i);
	int v = 0;
	do{
		v += (cal_time(ans)==k)?1:0;
		//cout<<cal_time(ans)<<" : ";
		//show(ans,ans.size());
	}while(next_permutation(ans.begin(),ans.end()));
	cout<<v<<endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}