#include <bits/stdc++.h>

using namespace std;

const int BS = 4000;
const int MAXN = 100005;

#define arr_dump(x, n) {cerr<<#x<<"[]: ";for(int i=1; i<=n; ++i) cerr<<x[i]<<" ";cerr<<endl;}
#define var_dump(x) cerr<<#x<<": "<<x<<'\n'

int Lin[2*MAXN], Dist[MAXN], Size[MAXN], I[MAXN], Pos[MAXN];
int now = 0, n;
long long total_paths = 0;

vector<pair<int, int>> G[MAXN];

void dfs(int node) {
	Lin[++now] = node;
	Size[node] = 1;

	for(auto vec : G[node]) {
		if(!Size[vec.first]) {
			Dist[vec.first] = Dist[node] + vec.second;
			dfs(vec.first);
			Size[node] += Size[vec.first];
		}
	}

	Lin[++now] = -node;
	total_paths += Size[node] - 1;
}

int T[MAXN];
void add(int pos, int val) {
	for(; pos <= n; pos += (pos & -pos))
		T[pos] += val;
}
int query(int val) {
	int i, pos = 0, sol = 0;
	for(i = 1; i <= n; i <<= 1);
	for(i >>= 1; i; i >>= 1)
		if(pos + i <= n && Dist[I[pos + i]] <= val)
			sol += T[pos + i], pos += i;
	return sol;
}

long long solve(int k) {
	long long ans = 0;

	memset(T, 0, sizeof(T));
	
	for(int i = 1; i <= 2 * n; ++i) {
		if(Lin[i] > 0) {
			add(Pos[Lin[i]], 1);
			ans -= query(Dist[Lin[i]] + k);			
		} else {
			ans += query(Dist[-Lin[i]] + k);
		}
	}
	return ans;
}

int32_t main() {
	int a, b, c;

	long long m;
	cin >> n >> m;
	for(int i = 2; i <= n; ++i) {
		cin >> a >> b >> c;
		G[a].push_back({b, c});
		G[b].push_back({a, c});
	}

	dfs(1);

	if(m > total_paths) {
		cout << -1;
		return 0;
	}


	for(int i = 1; i <= n; ++i) I[i] = i;
	sort(I + 1, I + n + 1, [](int a, int b) {return Dist[a] < Dist[b];});
	for(int i = 1; i <= n; ++i) Pos[I[i]] = i;

	int ans = -1;
	for(int step = (1 << 29); step; step >>= 1) {
		if(solve(step + ans) < m)
			ans += step;
	}

	cout << ans + 1;
	return 0;
}