#include <bits/stdc++.h>
using namespace std;

typedef __int128 ll;
typedef pair<int,int> ii;

void solve(){
	int n; cin >> n;
	long long ci; cin >> ci;
	ll C = ci;
	vector<tuple<int,int,ll>> v; // point, ev, price
	for (int i=0; i<n; i++){
		int a,b,c; cin >> a >> b >> c;
		v.push_back(make_tuple(a,0,c));
		v.push_back(make_tuple(b+1,1,c));
	}
	sort(v.begin(), v.end());
	ll curr = 0;
	ll answer = 0;
	ll lastpoint = -1;
	for (int i=0; i<n*2; i++){
		int j;
		ll change = 0;
		for (j=i; j<n*2 && get<0>(v[j]) == get<0>(v[i]); j++){
			if (get<1>(v[j]) == 0) change += get<2>(v[j]);
			else change -= get<2>(v[j]);
		}
		if (lastpoint == -1) lastpoint = get<0>(v[i]);
		ll dist = get<0>(v[i]) - lastpoint;
		if (dist > 0){
			answer = answer + min(dist * curr, dist * C);
		}
		curr += change;
		lastpoint = get<0>(v[i]);
		i = j-1;
	}
	vector<int> ans;
	while(answer > 0){
		ans.push_back(answer%10);
		answer = answer / (ll)10;
	}
	reverse(ans.begin(), ans.end());
	for (int i=0; i<ans.size(); i++) cout << ans[i];
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1; //cin >> t;
	while(t--) solve();

	return 0;
}
// NK

#include<bits/stdc++.h>
#define int long long int
//Compute XOR of all numbers from 1 to n in O(1) complexity
#define xor1toN(n) (n&((n&1)-1)&~1 | ((n>>1)^n)&1)
using namespace std;
const int M = 998244353;
const int mod = 1e9+7; 
const int inf = 1e18;
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
 
int power(int x,int y,int p){
	int res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}

void solve(){
	int n;
    cin>>n;
    int a[n];
    int b[n];
    int sum=0;
    int ans=INT_MAX;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        sum=a[i]+b[i];
        ans = min(sum,ans);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j)
            {
                int val =max(a[i],b[j]);
                ans = min(ans,val);
            }
        }
    }
    cout<<ans<<endl;
}

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