/**~~~~~~~~~~~~~~~~~~~~~~~~~~~**\
*  Bismillahir Rahmanir Rahim.  *
*          Imtiaz_rafi          *
*        PCIU, CHITTAGONG       *
\**~~~~~~~~~~~~~~~~~~~~~~~~~~~**/

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

typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef vector<pll> vll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] = {-1,+1,0,0,+1,-1,+1,-1};
ll dy[] = {0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;

#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file()  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define sl(a)   scanf("%lld",&a)
#define all(v)  v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,b,e) for(__typeof(e) i=(b)-(b>e);i!=(e)-(b>e);i+=1-2*(b>e))
#define trace(x)   cerr << #x << " = " << x << endl
#define mem(dp,i)  memset(dp,i,sizeof(dp))
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi acos(-1)
#define en '\n' //(1LL<<(3)) *2^3

template <class T> T power(T a,T b){a%=MOD;if(!a) return 0;T p=1;while(b>0){if(b&1){p*=a;p%=MOD;}a*=a;a%=MOD;b=b>>1;}return p;}
template <class T> void print(vector<T> &v){for(T u:v){cout<<u<<" ";}cout<<endl;}
template <class T> T gcd(T a, T b){return (b!=0?gcd<T>(b,a%b):a);}
template <class T> T lcm(T a, T b){return (a/gcd<T>(a,b)*b);}

int main()
{
    speed();
    ll t,a,i,b,c,ans=0,j,m = INT_MAX;
    cin>>a>>b;
    ll x[a][b];
    rep(i,0,a)
    {
        rep(j,0,b)
        {
            cin>>x[i][j];
            m = min(x[i][j],m);
        }
    }
    rep(i,0,a)
    {
        rep(j,0,b)
        {
            ans+= (x[i][j]-m);
        }
    }
    cout<<ans<<endl;

return 0;
}

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

using ll = long long;
using vll = vector<ll>;
using Pl = pair<ll, ll>;
int main() {
    ll N, P; cin >> N >> P;
    map<ll, ll> dat;
    for (int i = 0; i < N; i++) {
        ll A, B, C; cin >> A >> B >> C;
        dat[A] += C;
        dat[B+1] -= C;
    }
    ll sum = 0, p = 0;
    ll ans = 0;
    for (auto &v : dat) {
        ll now = v.first;
        if (sum > P) ans += (now-p)*P;
        else ans += (now-p)*sum;
        sum += v.second;
        p = now;
    }
    cout << ans << endl;
}

