#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;

int main() {
  int n; cin>>n;
  ll C; cin>>C;
  vector<P> e;
  rep(i,n) {
    ll a,b,c; cin>>a>>b>>c;
    e.emplace_back(a-1,c);
    e.emplace_back(b,-c);
  }
  sort(e.begin(),e.end());
  ll ans=0,cost=0,now=0;
  for(auto [x,y]:e) {
    if(x!=now) {
      ans+=min(C,cost)*(x-now);
      now=x;
    }
    cost+=y;
  }
  cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], c[maxn], d[maxn];
ll ans;
int n, l;
int main()
{
	scanf("%d%d", &n, &l);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	c[1] = a[1] - 1;
	for(int i = 2; i <= n; ++i) c[i] = a[i] - a[i - 1] - 1; 
	c[n + 1] = l - a[n];
	d[1] = b[1] - 1;
	for(int i = 2; i <= n; ++i) d[i] = b[i] - b[i - 1] - 1;
	d[n + 1] = l - b[n];
	/*for(int i = 1; i <= n + 1; ++i) cout << c[i] << ' '; cout << endl;
	for(int i = 1; i <= n + 1; ++i) cout << d[i] << ' '; cout << endl; */
	int l = 1;
	for(int i = 1; i <= n + 1; ++i)
		if(d[i])
		{
			while(l <= n + 1 && !c[l]) ++l;
			int r = l;
			while(r <= n + 1 && d[i] > 0)
			{
				d[i] -= c[r];
				++r;
			}
			if(d[i] < 0)
			{
				puts("-1");
				return 0;
			}
			//cout << l << ' ' << r - 1 << endl;
			if(i < l) ans += r - 1 - i;
			else if(i >= r) ans += i - l;
			else ans += r - l - 1;
			l = r;
		}
	printf("%lld\n", ans);
	return 0;
}