#include<bits/stdc++.h>
#define g return
using namespace std;int M,h=1e9,n,k,l=-1,r=1e6,a,b,i=1;vector<vector<int>> v;struct d{int m,s,f;};d x(int o,int p=h){if(v[o].size()==1&&o)g{0,-1,0};int t=h,s=-h,c=0,f=0;for(int& e:v[o])if(p-e){auto [j,y,z]=x(e,o);t=min(t,y);s=max(s,y);f|=z,c+=j;}t=abs(t);if(o){if(t<=s&&f){if(s)g{c,s-1,1};g{c,0,0};}if(t-M)g{c,-t-1,0};g{c+1,M-1,1};}if(t<=s&&f)g{c,0,0};g{c+1,0,0};}main(){cin>>n>>k;v.resize(n);for(;i<n;i++){cin>>a>>b;a--;b--;v[a].push_back(b);v[b].push_back(a);}while(r-l>1){M=(r+l)/2;if(M)(x(0).m>k?l:r)=M;else(n>k?l:r)=0;}cout<<r;}
#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 2e5 + 5;
int n,m,mid,ans;
std::vector<int> G[MAXN];
int f[MAXN],g[MAXN];

inline void dfs(int v,int fa=0){
    f[v] = 1e9;g[v] = -1e9;
    for(auto x:G[v]){
        if(x == fa) continue;
        dfs(x,v);
        f[v] = std::min(f[v],f[x]+1);
        g[v] = std::max(g[v],g[x]+1);
    }
    if(f[v] > mid) g[v] = std::max(g[v],0);
    if(f[v]+g[v] <= mid) g[v] = -1e9;
    if(g[v] == mid) ++ans,g[v] = -1e9,f[v] = 0;
}

inline bool chk(int x){
    mid = x;ans = 0;dfs(1);
    if(g[1] != -1e9) ++ans;
    return ans <= m;
}

int main(){
    scanf("%d%d",&n,&m);
    FOR(i,2,n){
        int u,v;scanf("%d%d",&u,&v);
        G[u].pb(v);G[v].pb(u);
    }
    int l = 0,r = n,ans = -1;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(chk(mid)) ans = mid,r = mid-1;
        else l = mid+1;
    }
    printf("%d\n",ans);
    return 0;
}
