#include using namespace std; const int NMax = 1e5 + 5; vector < pair < int, int > > G[NMax]; vector < int > A; bool check[NMax]; void DFS(const int &node, const int value){ for(auto it: G[node]){ if(!check[it.first]){ A.push_back(value + it.second); check[it.first] = 1; DFS(it.first, value + it.second); DFS(it.first, 0); check[it.first] = 0; } } } int main(){ #ifndef ONLINE_JUDGE freopen("debug.in", "r", stdin); #endif // ONLINE_JUDGE int n, m, a, b, c; cin >> n >> m; for(int i = 1; i < n; i++){ cin >> a >> b >> c; G[a].push_back({b, c}); G[b].push_back({a, c}); } check[1] = 1; DFS(1, 0); if(A.size() >= m){ nth_element(A.begin(), A.begin() + m - 1, A.end()); cout << A[m - 1]; } else { cout << "-1"; } return 0; }