#include<bits/stdc++.h>
using namespace std;
// #define LOCAL

typedef long long ll;
#ifdef LOCAL
    const int N = 105;
#else
    const int N = 2e5 + 105;
#endif
const int INF = 0x3f3f3f3f;
int n, k, tot = 0, Mid;
vector<int> edge[N];
int f[N]; // 离最远的未被覆盖的关键点
int g[N]; // 离最近的已经选择的点
void dfs(int u, int fa){
    f[u] = -INF;
    g[u] = INF;
    for(auto v : edge[u]){
        if(v == fa) continue;
        dfs(v, u);
        f[u] = max(f[u], f[v] + 1);
        g[u] = min(g[u], g[v] + 1);
    }
    f[u] = max(f[u], 0);
    if(f[u] + g[u] <= Mid){
        f[u] = -INF;
    }
    if(f[u] == Mid){
        ++tot;
        f[u] = -INF;
        g[u] = 0;
    }
}
bool check(int mid){
    Mid = mid;
    tot = 0;
    dfs(1, 0);
    tot += f[1] >= 0;
    return tot <= k;
}
void solve() {
    cin >> n >> k;
    for(int i = 1; i < n; ++i){
        int u, v; cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    int l = 0, r = n, mid, ans = n;
    while(l <= r){
        mid = l + r >> 1;
        if(check(mid)){
            ans = min(ans, mid);
            r = mid - 1;
        }else{
            l = mid + 1;
        }
    }
    cout << ans << endl;
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    cout << "start Debug" << endl;
#endif
    int _ = 1;
    // cin >> _;
    for(int i = 1; i <= _; ++i) solve(); 
}
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

struct tree{
  vector<vector<int>> G,son,ancestor;
  vector<int> depth,parent;
  queue<int> que;
  int n,root=-1;
  bool made_lca=false;

  tree(int n_):G(n_),son(n_),parent(n_,-1),depth(n_,-1),ancestor(n_),n(n_){
    for(int i=0;i<n_;i++)ancestor[i].resize(30);
  }

  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  inline void reset_root(){
    root=-1;
    fill(depth.begin(),depth.end(),-1);
    fill(parent.begin(),parent.end(),-1);
    for(auto &p:ancestor)for(int &q:p)q=-1;
    for(auto &p:son)p.resize(0);
    made_lca=false;
  }

  void have_root(int r){
    reset_root();
    root=r;
    que.push(r);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:G[p]){
        if(parent[p]==q)continue;
        son[p].push_back(q);
        parent[q]=p;
        que.push(q);
      }
    }
  }

  void set_depth(){
    assert(~root);
    depth[root]=0;
    que.push(root);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:son[p]){
        depth[q]=depth[p]+1;
        que.push(q);
      }
    }
  }

  inline void make_lca(){
    assert(~root);
    if(depth[root]<0)set_depth();
    for(int i=0;i<G.size();i++)ancestor[i][0]=parent[i];
    for(int j=1;j<30;j++)
      for(int i=0;i<G.size();i++)
        if(~ancestor[i][j-1])
          ancestor[i][j]=ancestor[ancestor[i][j-1]][j-1];
    made_lca=1;
  }

  int lca(int u,int v){
    if(!made_lca)make_lca();
    if(depth[u]>depth[v])swap(u,v);
    int diff=depth[v]-depth[u],cnt=0;
    while(diff){
      if(diff&1)v=ancestor[v][cnt];
      cnt++;
      diff>>=1;
    }
    if(u==v)return u;
    for(int k=28;k>=0;k--)
      if(ancestor[u][k]!=ancestor[v][k])
        u=ancestor[u][k],v=ancestor[v][k];
    return ancestor[u][0];
  }
};
typedef pair<int,int> P;
const double TIMELIMIT=2.98*CLOCKS_PER_SEC;
int ans=234567;
priority_queue<P> que;
queue<P> tmp;

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  clock_t start = clock();
  int n,k;cin>>n>>k;
  tree t(n);
  REP(i,n-1){
    int a,b;cin>>a>>b;a--;b--;
    t.add_edge(a,b);
  }
  int ans=n;
  t.have_root(0);
  t.set_depth();
  int ng=-1,ok=n;
  while(ok-ng>1){
    int m=(ok+ng)>>1;
    //cout<<"M:"<<m<<endl;
    vector<int> used(n,-1),in(n);
    REP(i,n)in[i]=t.son[i].size();
    while(que.size())que.pop();
    REP(i,n)if(!in[i])que.push(P(t.depth[i],i));
    int cnt=0;
    while(que.size()){
      P quenonaka=que.top();que.pop();
      int p=quenonaka.second,D=quenonaka.second;
      if(~used[p])continue;//ここは今回のやつを助けるやつ探すところ
      cnt++;if(cnt>k){
        //cout<<"WA"<<p<<endl;
        break;
      }
      int now=p;
      for(int i=0;i<m&&now!=t.root;i++)now=t.parent[now];
      //cout<<p<<" "<<now<<endl;
      while(tmp.size())tmp.pop();
      tmp.push(P(now,m));//nowが今回新しく塗るやつ
      used[now]=m;if(now!=t.root&&!--in[t.parent[now]])que.push(P(t.depth[t.parent[now]],t.parent[now]));
      while(tmp.size()){
        P q=tmp.front();tmp.pop();
        int v=q.first,aa=q.second;
        for(int w:t.son[v]){
          if(used[w]<0){
            used[w]=aa-1;
            if(aa>1)tmp.push(P(w,aa-1));
          }
          else if(used[w]<aa-1){
            used[w]=aa-1;
            tmp.push(P(w,aa-1));
          }
        }
        if(v!=t.root){
          int PA=t.parent[v];
          if(used[PA]<0){
            used[PA]=aa-1;
            if(PA!=t.root&&!--in[t.parent[PA]])que.push(P(t.depth[t.parent[PA]],t.parent[PA]));
            if(aa>1)tmp.push(P(PA,aa-1));
          }
          else if(used[PA]<aa-1){
            used[PA]=aa-1;
            tmp.push(P(PA,aa-1));
          }
        }
      }
    }
    if(cnt>k)ng=m;
    else ok=m;
  }
  cout<<ok<<endl;
}
