#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
return flag ? out : -out;
}
int h[maxn],ne;
struct EDGE{
int to,nxt;
}ed[maxn * 2];
void build(int u,int v){
ed[++ne] = (EDGE){v,h[u]}; h[u] = ne;
ed[++ne] = (EDGE){u,h[v]}; h[v] = ne;
}
int n,t,tag[maxn],dep[maxn],fa[maxn];
int st[maxn];
void dfs1(int u){
Redge(u) if ((to = ed[k].to) != fa[u]){
fa[to] = u; dep[to] = dep[u] + 1;
dfs1(to);
if (tag[to]) tag[u] = true;
}
if (u == n) tag[u] = true;
}
int dfs2(int u,int f){
int mx = 0;
Redge(u) if ((to = ed[k].to) != f){
mx = max(mx,dfs2(to,u) + 1);
}
return mx;
}
void work(){
dfs1(1);
if (t >= dep[n]){puts("0"); return;}
int rt = 0,ans = 0;
REP(i,n) if (tag[i] && dep[i] == t){rt = i; break;}
REP(i,n) if (tag[i]) st[dep[i]] = i;
//for (int i = 0; i <= dep[n]; i++) printf("%d ",st[i]); puts("");
int mx = 0;
Redge(rt) if (!tag[to = ed[k].to] || to == fa[rt]){
mx = max(mx,dfs2(to,rt) + 1);
}
int tmp,len = dep[n] - dep[rt];
if (mx >= len) tmp = len;
else tmp = mx + (len - mx + 1) / 2;
ans = tmp;
//cout << ans << endl;
for (int i = dep[rt] + 1; i < dep[n]; i++){
int u = st[i];
//printf("[%d]\n",u);
int d = dep[n] - dep[rt] - 3 * (i - dep[rt]),mx = 0;
if (d <= 0) break;
Redge(u) if (!tag[to = ed[k].to]){
mx = max(mx,dfs2(to,u) + 1);
}
if (mx >= d) tmp = d;
else tmp = mx + (d - mx + 1) / 2;
//cout << d << ' ' << tmp << ' ' << i << ' ' << dep[rt] << endl;
ans = max(ans,tmp + i - dep[rt]);
}
printf("%d\n",ans);
}
int main(){
n = read(); t = read();
for (int i = 1; i < n; i++) build(read(),read());
work();
return 0;
}