#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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

#define mp make_pair


const int MOD =  998244353;

int mul(int a, int b) {
    return (1LL * a * b) % MOD;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=MOD) s-=MOD;
    return s;
}

int sub(int a, int b) {
    int s = (a+MOD-b);
    if (s>=MOD) s-=MOD;
    return s;
}

int po(int a, ll deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, MOD-2);
}


mt19937 rnd(time(0));

/*
const int LIM = 3e5 + 5;

vector<int> facs(LIM), invfacs(LIM);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i);
    invfacs[LIM-1] = inv(facs[LIM-1]);
    for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


/*struct DSU
{
    vector<int> sz;
    vector<int> parent;
    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        find_set(a);
        find_set(b);

        a = find_set(a);
        b = find_set(b);

        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        };
    }

    DSU (int n)
    {
        parent.resize(n);
        sz.resize(n);
        for (int i = 0; i<n; i++) make_set(i);
    }
};*/

vector<vector<int>> G;

int n, k;

vector<int> parent;
vector<int> depth;
vector<vector<int>> children;

void dfs(int v, int par = -1)
{
    for (auto it: G[v]) if (it!=par)
    {
        children[v].push_back(it);
        depth[it] = depth[v] + 1;
        parent[it] = v;
        dfs(it, v);
    }
}

set<pair<int, int>> worst;
vector<bool> deleted;
vector<int> deleting;

void del(int v, int dist)
{
    if (!deleted[v])
    {
        worst.erase(mp(depth[v], v)); deleted[v] = true;
    }
    if (dist<=deleting[v]) return;
    deleting[v] = dist;

    if (dist==0) return;

    for (auto it: G[v]) del(it, dist-1);
}

bool check(int d)
{
    worst.clear();
    for (int i = 0; i<n; i++) worst.insert(mp(depth[i], i));
    deleted.clear(); deleted.resize(n);
    deleting.clear(); deleting.resize(n);

    int cnt = 0;
    while (!worst.empty())
    {
        cnt++;
        //cout<<"Iter "<<cnt<<": "<<endl;

        //for (auto it: worst) cout<<it.first<<' '<<it.second<<endl;

        auto it = *prev(worst.end());
        if (it.first<=d)
        {
            return (cnt<=k);
        }

        int deleting = it.second;
        for (int i = 0; i<d; i++) deleting = parent[deleting];
        //cout<<"Deleting: "<<deleting<<endl;
        del(deleting, d);
    }
    if (worst.empty()) return (cnt<=k);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    cin>>n>>k;

    G.resize(n);
    for (int i = 0; i<n-1; i++)
    {
        int u, v; cin>>u>>v; u--; v--;
        G[u].push_back(v); G[v].push_back(u);
    }

    parent.resize(n); depth.resize(n); children.resize(n);

    parent[0] = -1;
    dfs(0);

    int L = 0; int R = n;
    while (R-L>1)
    {
        int mid = (L+R)/2;
        if (check(mid)) R = mid; else L = mid;
    }

    cout<<R<<endl;



}
