#include <bits/stdc++.h>
using namespace std;
const int nax = (int)1e5 + 100;
const int INF = (int)1e9 + 47;
int C[nax], D[nax];
vector<int > G[nax];
int n, k;
bool cmp(const int &a, const int& b)
{
return D[a] < D[b];
}
void dfs(int a, int p, int x)
{
int id = -1;
for(int i = 0; i < G[a].size(); i++)
{
if(G[a][i] == p)
{
id = i;
continue;
}
dfs(G[a][i], a, x);
}
if(id!=-1)
{
swap(G[a].back(), G[a][id]);
G[a].pop_back();
}
sort(G[a].begin(), G[a].end(), cmp);
if(G[a].empty())
{
D[a] = 0;
C[a] = 1;
return ;
}
int sum_c = 0;
for(int i = 0; i < G[a].size(); i++)
{
sum_c += C[G[a][i]];
}
D[a] = D[G[a][0]] + 1;
C[a] = sum_c;
for(int i = 1; i < G[a].size(); i++)
{
if(D[G[a][i]] + D[G[a][i - 1]] + 2 <= x)
{
C[a] = sum_c - i;
D[a] = D[G[a][i]] + 1;
}
else
break;
}
if(D[a] > x)
{
D[a] = 0;
C[a] = sum_c + 1;
}
}
int main()
{
cin >> n >> k;
for(int i = 0; i < n - 1;i++)
{
int a, b;
cin >> a >> b;
--a, --b;
G[a].push_back(b);
G[b].push_back(a);
}
int l = -1, r = n - 1;
while(r - l > 1)
{
int mid = (l + r) / 2;
dfs(0, -1, mid);
if(C[0] <= k)
r = mid;
else
l = mid;
}
cout << r << '\n';
return 0;
}