#include <bits/stdc++.h>

using namespace std;

const int BS = 256;
const int MAXN = 100005;

int Val[MAXN], B[MAXN], E[MAXN], Sort[MAXN], Dist[MAXN], Size[MAXN];
int now = 0, n;
int total_paths = 0;

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

void dfs(int node) {
	now += 1;
	Val[now] = Dist[node];
	B[node] = now;
	Size[node] = 1;

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

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

void preprocess() {
	for(int i = 1; i < now; ++i)
		Sort[i] = Val[i];
	for(int i = 0; i < now; i += BS)
		sort(Sort + i, Sort + i + BS);
}

int query(int l, int r, int k) {	
	int ans = 0;
	for(int i = l; i <= r;) {
		if(i % BS == 0 && i + BS - 1 <= r) {
			ans += upper_bound(Sort + i, Sort + i + BS, k) - Sort - i;
			i += BS;
		} else {
			if(Val[i] <= k)
				ans += 1;
			i += 1;
		}
	}
	return ans;
}

int solve(int k) {
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		ans += query(B[i] + 1, E[i], k + Dist[i]);
	}
	return ans;
}

int main() {
	int a, b, m, c;
	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);
	preprocess();

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

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

	cout << ans - 1;
	return 0;
}