#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long a;
    long long b;
    long long c;
} nh[200005];
long long q[400005];
long long qq[800005];
int main()
{
    long long n,C;
    scanf("%lld%lld",&n,&C);
    int num=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld%lld",&nh[i].a,&nh[i].b,&nh[i].c);
        num++;
        q[num]=nh[i].a;
        num++;
        q[num]=nh[i].b;
    }
    sort(q+1,q+num+1);
    int len=unique(q+1,q+num+1)-q;
    for(int i=1;i<=n;i++)
    {
        int l=1,r=len,ans1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(q[mid]==nh[i].a)
            {
                ans1=mid;
                break;
            }
            else if(q[mid]>nh[i].a)
            {
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        l=1,r=len;
        int ans2;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(q[mid]==nh[i].b)
            {
                ans2=mid;
                break;
            }
            else if(q[mid]>nh[i].b)
            {
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        qq[2*ans1-1]+=nh[i].c;
        qq[2*ans2]-=nh[i].c;
    }
    long long now=0;
    long long ans=0;
    //printf("%d\n",len);
    for(int i=1;i<=2*len-1;i++)
    {
        //if(i%2==0) printf("%d %lld %lld %lld\n",i,now,q[i/2+1],q[i/2]);
        //else printf("%d %lld\n",i,now);
        now=now+qq[i];
        if(i%2==0) ans=ans+(q[i/2+1]-q[i/2]-1)*min(C,now);
        else ans=ans+min(C,now);
    }
    printf("%lld\n",ans);
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 2e5+10;
int dp_pego[N], dp_val[N], dp_qnt[N];

vector<int> g[N];
int mdist;

void dfs(int no, int from){
	//prin(no);
	int dist_prox_pego = INT_MAX/2, dist_longe_need = 0;
	dp_qnt[no] = 0;
	for(auto &it : g[no]){
		if(it==from) continue;
		dfs(it,no);
		dp_qnt[no]+=dp_qnt[it];
		if(dp_pego[it]){
			rmin(dist_prox_pego,dp_val[it]+1);
		} else{
			rmax(dist_longe_need,dp_val[it]+1);
		}
	}
	if(dist_prox_pego<=mdist){
		if(dist_prox_pego+dist_longe_need<=mdist){
			dp_pego[no] = 1;
			dp_val[no] = dist_prox_pego;
		} else{
			if(dist_longe_need==mdist){
				dp_qnt[no]++;
				dp_pego[no] = 1;
				dp_val[no] = 0;
			} else{
				dp_pego[no] = 0;
				dp_val[no] = dist_longe_need;
			}
		}
	} else{
		if(dist_longe_need==mdist){
			dp_qnt[no]++;
			dp_pego[no] = 1;
			dp_val[no] = 0;
		} else{
			dp_pego[no] = 0;
			dp_val[no] = dist_longe_need;
		}
	}
	if(no==0 and !dp_pego[no]) dp_qnt[no]++;
}

int need(int _mdist){
	mdist = _mdist;
	dfs(0,-1);
	return dp_qnt[0];
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n, k; cin >> n >> k;
	fr(i,n-1){
		int a, b; cin >> a >> b; a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	int lo = 1, hi = n;
	while(lo<hi){
		int mid = (lo+hi)/2;
		if(need(mid)<=k) hi = mid;
		else lo = mid+1;
	}
	cout << lo << "\n";
}