#include <bits/stdc++.h>
 
#define lowbit(x) ((x) & (-x))
using namespace std;
 
typedef long long LL;
 
const int N = 200005;
 
int n, e;
int a[N], b[N], c[N], d[N * 4];
LL m, f[N * 4];
 
void init() {
    memset(f, 0, sizeof(f));
}
 
void add(int p, int val) {
    for (; p < e; p += lowbit(p)) f[p] += val;
}
 
LL cal(int p) {
    LL ans = 0;
    for (; p > 0; p -= lowbit(p)) ans += f[p];
    return ans;
}
 
void gao() {
    e = 0;
    d[e++] = 0;
    for (int i = 0; i < n; i++) {
        d[e++] = a[i], d[e++] = a[i] + 1;
        d[e++] = b[i], d[e++] = b[i] + 1;
    }
    sort(d, d + e);
    e = unique(d, d + e) - d;
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(d, d + e, a[i]) - d;
        b[i] = lower_bound(d, d + e, b[i]) - d;
        // printf("l= %d, r= %d, c= %d\n", a[i], b[i], c[i]);
    }
 
    init();
    for (int i = 0; i < n; i++) {
        add(a[i], c[i]);
        add(b[i] + 1, -c[i]);
    }
 
    LL ans = 0;
    for (int i = 1; i < e - 1; i++) {
        LL tmp = cal(i);
        // printf("i= %d %d %lld %lld\n", i, d[i], tmp, tmp * (d[i + 1] - d[i]));
        ans += min(m, tmp) * (d[i + 1] - d[i]);
    }
    cout << ans << '\n';
}
 
 
inline bool scan_d(int &num)  
{
        char in;bool IsN=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;}
        else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){
                num*=10,num+=in-'0';
        }
        if(IsN) num=-num;
        return true;
}
 
int main() {
    scan_d(n);
    scanf("%lld", &m);
        for (int i = 0; i < n; i++) scan_d(a[i]), scan_d(b[i]), scan_d(c[i]);
        gao();
    return 0;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std;
using namespace __gnu_pbds; 

#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define MAXN        200001

typedef tree<int, null_type, 
     less_equal<int>, rb_tree_tag,
          tree_order_statistics_node_update> 
    Ordered_set; 
// s.find_by_order(idx) find using index..!
// s.order_of_key(val) Gives iterator to the key..! 

/* First solve then try Writing Code.. And be cool ^_^ and calm. */
 
int n, a[MAXN]; 

int go(int l, int r)
{
    if(r < l)
        return 0;
    if(r == l)
        return a[r];
    int idx = l;
    for(int i=l;i<=r;i++)
    {
        if(a[i] < a[idx])
            idx = i;
    }

    int fi = go(l, idx-1);
    int se = go(idx+1, r);

    if(a[idx]*(r-l+1) > max(fi, se))
        return a[idx]*(r-l+1);
    else
        return max(fi, se);
}

void solve(){

    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    cout<<go(0, n-1)<<endl;
}

int32_t main()
{    
    int t=1;
    // cin>>t;
    while(t--) solve();
    
    return 0;
}
