#include using namespace std; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) { } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; vector> g; int ans = -1; int dfs( int n, int p, int m, int d ) { //cout << n << " " << p << " " << m << " " << d << endl; if( m == 1 ) return d; for( int e : g[n] ) { if( e == p ) continue; int res = dfs( e, n, m - 1, d + 1 ); ans = min( ans, res ); } return ans; } int main() { int N, K; cin >> N >> K; UnionFind uf( N ); g = vector>( N ); for( int i = 0; i < N - 1; i++ ) { int a, b; cin >> a >> b; a--; b--; uf.unionSet( a, b ); g[a].push_back( b ); g[b].push_back( a ); } if( K <= uf.size( 0 ) ) { ans = INT32_MAX; ans = dfs( 0, -1, K, 0 ); } cout << ans << endl; }