#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
 
#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
 
const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int h[MAX], order[MAX], p[MAX];
bool covered[MAX];
int n, k;

void calc_h(int s) {
    for (int u : adj[s]) {
        if (u != p[s]) {
            h[u] = h[s] + 1;
            p[u] = s;
            calc_h(u);
        }
    }
}

void cover(int u, const int max_d, int cur_d = 0, int prev = -1) {
    covered[u] = true;
    if (cur_d == max_d) return;
    for (int v : adj[u]) {
        if (v == prev) continue;  
        cover(v, max_d, cur_d + 1, u);
    }
}

bool ok(int d) {
    memset(covered, false, sizeof covered);
    int need = 0;
    fori (i, 0, n) {
        int u = order[i];
        if (covered[u]) continue;
        int y = u;
        while (y != 1 && h[u] - h[y] < d) {
            y = p[y];
        }
        cover(y, d);
        need++;
        if (need > k) return false;
    }
    return true;
}

void solve() {
    cin >> n >> k;
    fori (i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    calc_h(1);

    iota(order, order + n, 1);
    sort(order, order + n, [&] (int lhs, int rhs) {
        return h[lhs] > h[rhs];
    });

    int left = 0, right = n;
    int ans = -1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (ok(mid)) {
            right = mid - 1;
            ans = mid;
        }
        else {
            left = mid + 1;
        }
    }
    assert(ans != -1);
    cout << ans << endl;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

#include<bits/stdc++.h>
#define N 200005
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cerr<<#x<<"="<<x<<endl;
#define db2(x,y) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int rd(){
    int res=0,c,f=0; while(!isdigit(c=getchar()))f=c=='-';
    do res=(res<<1)+(res<<3)+(c^48);
    while(isdigit(c=getchar()));
    return f?-res:res;
}
struct edge{int to,nxt;}e[N<<1];
int n,knum,head[N];
void link(int s,int t,int n){
    e[n]=(edge)<%t,head[s]%>;
    head[s]=n;
}
int v[N],dep[N];
struct cmp{bool operator ()(const int &a,const int &b){return dep[a]>dep[b];}};
int ffa[N][18];
void dfs(int x,int f,int d){
    ffa[x][0]=f,dep[x]=d;
    for(int i=1;1<<i<=n;i++)ffa[x][i]=ffa[ffa[x][i-1]][i-1];
    for(int i=head[x];i;i=e[i].nxt){
        int to=e[i].to;
        if(to==f)continue;
        dfs(to,x,d+1);
    }
}
int dis[N];
int Fa(int x,int d){
    for(int i=0;1<<i<=d;i++)if(1<<i&d)x=ffa[x][i];
    return !x?1:x;
}
void Mark(int x,int d){
    if(dis[x]==d)return;
    for(int i=head[x];i;i=e[i].nxt){
        int to=e[i].to;
        if(~dis[to]&&dis[to]<=dis[x]+1)continue;
        dis[to]=dis[x]+1,Mark(to,d);
    }
}
bool check(int k){
    int now=0;
    Ms(dis,-1);
    for(int i=1;i<=n;i++){
        int x=v[i];
        if(~dis[x])continue;
        ++now,x=Fa(x,k),dis[x]=0,Mark(x,k);
    }
    return now<=knum;
}
int main(){
    n=rd(),knum=rd();
    for(int i=1;i<n;i++){
        int s=rd(),t=rd();
        link(s,t,i<<1);
        link(t,s,i<<1|1);
    }
    dfs(1,0,1);
    for(int i=1;i<=n;i++)v[i]=i;
    sort(v+1,v+1+n,cmp());
    int l=1,r=n,res=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))r=mid-1,res=mid;
        else l=mid+1;
    }
    printf("%d\n",res);
    return 0;
}
