#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;
}

#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 200001;

int n, k;
vector <int> v[N];

pair <int, int> dfs(int node, int pnode, int f){
    int cnt = 0;
    int neg = 0, pos = 0;
    for(auto &i : v[node]){
        if(i == pnode) continue;
        auto c = dfs(i, node, f);
        cnt += c.first;
        if(c.second < 0) neg = max(neg, -c.second);
        else pos = max(pos, c.second);
    }
    if(pos <= neg - 1) return make_pair(cnt, -(neg - 1));
    if(pos == f) return make_pair(cnt + 1, -f);
    return make_pair(cnt, pos + 1);
}
int calc(int mid){
    auto p = dfs(1, 0, mid);
    return p.first + (p.second > 0);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0 ; i < n - 1 ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int l = 1, r = n;
    while(l <= r){
        int mid = (l + r) / 2;
        if(calc(mid) <= k) r = mid - 1;
        else l = mid + 1;
    }
    cout << l << endl;
}
