#include <bits/stdc++.h>
using namespace std;
const int max_N = 100000 + 10;
const int T = 17 + 5;
int c, n, k, ti[max_N], h[max_N], anc[T][max_N];
vector<int> adj[max_N];
set<pair<int, int> > q;
set<pair<int, int> >::iterator it;
void dfs(int v, int par = -1) {
  ti[v] = c++;
  for (int u : adj[v]) {
    if (u != par) {
      h[u] = h[v] + 1;
      anc[0][u] = v;
      dfs(u, v);
    }
  }
}
int up(int u, int d) {
  for (int i = 0; i < T; i++)
    if (d & (1 << i)) u = anc[i][u];
  return u;
}
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  int d = h[u] - h[v];
  u = up(u, d);
  if (u == v) return d;
  for (int i = T - 1; i >= 0; i--) {
    if (anc[i][u] != anc[i][v]) {
      d += 2 * (1 << i);
      u = anc[i][u];
      v = anc[i][v];
    }
  }
  return d + 2;
}
int f(int cur) {
  int nex = (it != q.end()) ? it->second : q.begin()->second;
  int pre = (it != q.begin()) ? (--it)->second : (--q.end())->second;
  return lca(pre, cur) + lca(cur, nex) - lca(pre, nex);
}
bool check(int x) {
  int d(0);
  q.clear();
  for (int i = 0; i < x; i++) q.insert({ti[i], i});
  int tmp = q.begin()->second;
  for (it = ++(q.begin()); it != q.end(); it++) {
    d += lca(it->second, tmp);
    tmp = it->second;
  }
  d += lca(q.begin()->second, tmp);
  if (d / 2 < k) return true;
  for (int i = 0; i < n - x; i++) {
    pair<int, int> t = {ti[i], i};
    q.erase(t);
    it = q.lower_bound(t), d -= f(t.second);
    t = {ti[i + x], i + x};
    it = q.lower_bound(t), d += f(t.second);
    q.insert(t);
    if (d / 2 < k) return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int a, b;
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    adj[--a].push_back(--b), adj[b].push_back(a);
  }
  dfs(0);
  for (int i = 1; i < T; i++)
    for (int j = 0; j < n; j++) anc[i][j] = anc[i - 1][anc[i - 1][j]];
  int st = 0, en = n + 1;
  while (en - st > 1) {
    int mid = (st + en) / 2;
    if (check(mid))
      st = mid;
    else
      en = mid;
  }
  cout << st << "\n";
  return 0;
}
