#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int maxn=2e5+5;
struct node{
    int l,r,x;
}p[maxn];
ll a[maxn*2];
int b[maxn*2];
map<int,int>pos;

int main(){
    int n,c;
    scanf("%d%d",&n,&c);
    int cnt=0;
    for(int i=1;i<=n;i++){
        int l,r,x;
        scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].x);
        b[++cnt]=p[i].l;
        b[++cnt]=p[i].r+1;
    }
    sort(b+1,b+1+cnt);
    cnt= unique(b+1,b+1+cnt)-b-1;
    for(int i=1;i<=cnt;i++){
        pos[b[i]]=i;
    }
    for(int i=1;i<=n;i++){
        a[pos[p[i].l]]+=p[i].x;
        a[pos[p[i].r+1]]-=p[i].x;
    }
    b[cnt+1]=b[cnt]+1;

    ll ans=0;
    for(int i=1;i<=cnt;i++){
        a[i]+=a[i-1];
        ans+=(b[i+1]-b[i])*min(a[i],1ll*c);
    }
    printf("%lld\n",ans);

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

template<class Tp>
void chmax (Tp &a, const Tp &b) {
	if (a < b) a = b;
}

int main() {
	int n;
	long long t;
	std::cin >> n >> t;
	std::vector<long long> a(n);
	for (auto &e : a) std::cin >> e;
	
	int n1 = (n >> 1), n2 = n - n1;
	long long time = 0;
	std::vector<long long> times(1 << n1, 0);
	for (int s = 1; s < (1 << n1); s++) {
		const int tmp = (s ^ (s >> 1));
		const int i = __builtin_ctz(s);
		if (tmp >> i & 1) time += a[i];
		else time -= a[i];
		times[s] = time;
	}
	
	time = 0;
	std::sort(times.begin(), times.end());
	times.erase(std::unique(times.begin(), times.end()), times.end());
	long long ans = *std::prev(std::upper_bound(times.begin(), times.end(), t));
	for (int s = 1; s < (1 << n2); s++) {
		const int tmp = (s ^ (s >> 1));
		const int i = __builtin_ctz(s);
		if (tmp >> i & 1) time += a[n1 + i];
		else time -= a[n1 + i];
		if (time <= t) {
			chmax(ans, time + *std::prev(std::upper_bound(times.begin(), times.end(), t - time)));
		}
	}
	
	std::cout << ans << '\n';
	return 0;
}