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

struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;

using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;

#define pb push_back
#define mp make_pair
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" <<endl;
#define kd(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m";
#define kdl(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << ", \033[m";
#define kde(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m" << endl;

inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}

int main()
{
    int n = in_int();
    ll C = in_ll();
    priority_queue<pii,vector<pii>,greater<pii>> q;
    vector<tuple<int,int,int>> v(n);
    rep(i,n) {
        int a = in_int();
        int b = in_int() + 1;
        int c = in_int();
        v[i] = {a,b,c};
        q.emplace(mp(a,i));
        q.emplace(mp(b,i));
    }
    int time = 1;
    ll cost = 0;
    ll ans =0;
    while (!q.empty()) {
        auto [new_time,_] = q.top();
        ans += min(cost, C) * (new_time - time);
        time = new_time;
        //kde(time);
        bool retry = true;
        do {
            if (cost < 0) return 1;
            auto [t,i] = q.top();
            if (t > time) retry = false;
            else {
                q.pop();
                auto [a,b,c] = v[i];
                if (t == a) {
                    //kd("\tin"); kd(c);
                    cost += c;
                } else if (t == b) {
                    //kd("\tout"); kd(c);
                    cost -= c;
                } else {
                    debug("raise");
                    return 1;
                }
                //kde(cost);
            }
        } while (retry && !q.empty());
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
 
using namespace std;
using i128 = __int128_t;
using u128 = __uint128_t;

//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 
    
//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< std::vector<int> > vvi;
typedef std::vector< std::vector<long long> > vvl;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long double PI = 3.141592653589793238;
const long long pi = 31415926;
const long long inf = 1000000000000000000;
const long long small_inf = 100000000000000;
 
ll modpow(ll x, ll n, ll mod = MOD){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;}
ll power(ll x, ll n){ ll res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;}

void init()
{

}

void solve()
{
    ll ans=0;
    string s;
    cin>>s;
    int n = s.length();
    vll v(26,0);
    repd(i,n-1,0)
    {
        v[s[i]-'a']++;
        if(i==n-1)
            continue;
        if(s[i]==s[i+1])
        {
            int x  = 0, y=v[s[i]-'a'];
            rep(i,26)
            {
                x+=v[i];
                v[i]=0;
            }
            ans+=x-y;
            v[s[i]-'a']=x;
        }
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t23 = 1, tt23=1;
    // cin>>t23;    
    init();
    while(tt23<=t23)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt23++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}