#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 100005;


int Size[MAXN], Dist[MAXN], Parent[MAXN], ParentCost[MAXN];
int n;
long long total_paths = 0;

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


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

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

	total_paths += Size[node] - 1;
}

long long solve(int k) {
	long long ans = 0;
	for(int i = 1; i <= n; ++i) {
		--ans;
		for(int j = i, d = 0; d <= k && j; d += ParentCost[j], j = Parent[j])
			++ans;
	}
	return ans;
}

void Read(int &a) {
	cin >> a;
}

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

	dfs(1);

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

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

	cout << ans + 1;
	return 0;
}