#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  register int data = 0, w = 1;
  register char ch = 0;
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
  return w * data;
}
const int MAX_N = 1e5 + 5;
int N, K;
set<pair<int, int> > G[MAX_N], st;
int main() {
  N = gi(), K = gi();
  for (int i = 1; i < N; i++) {
    int u = gi(), v = gi(), w = gi();
    G[u].insert(make_pair(v, w));
    G[v].insert(make_pair(u, w));
  }
  for (int i = 1; i <= N; i++)
    if (G[i].size() == 1) st.insert(make_pair(G[i].begin()->second, i));
  int ans = 0;
  while (st.size() > 2 || N > K) {
    ans = st.begin()->first;
    int x = st.begin()->second;
    st.erase(st.begin());
    int fa = G[x].begin()->first;
    G[fa].erase(G[fa].lower_bound(make_pair(x, 0)));
    N--;
    if (G[fa].size() == 1)
      st.insert(make_pair(G[fa].begin()->second + ans, fa));
  }
  printf("%d\n", ans);
  return 0;
}
