#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001 * 101, MOD = 1e9 + 7;
vector<int> a[MAXN];
int par[MAXN][20] = {}, st[MAXN], en[MAXN] = {};
int tme = 0, n, t[MAXN] = {};
;
set<int> cur, w;
void dfs(int u, int p, int k) {
  par[u][0] = p;
  t[u] = k;
  for (int i = 1; i < 20; i++) {
    par[u][i] = par[par[u][i - 1]][i - 1];
  }
  st[u] = tme++;
  for (auto v : a[u]) {
    if (v != p) dfs(v, u, k + 1);
  }
  en[u] = tme;
}
int get(int x) {
  auto u = cur.lower_bound(st[x]);
  if (u == cur.end() || (*u) >= en[x]) return 0;
  u = cur.end();
  u--;
  if (*cur.begin() >= st[x] && *u < en[x]) return 1;
  return 2;
}
pair<int, int> solve1(int x) {
  int y = x, ans = 0;
  ;
  for (int i = 19; i > -1; i--) {
    if (par[x][i] && get(par[x][i]) == 0) {
      ans += 1 << i;
      x = par[x][i];
    }
  }
  return {ans + 1, par[x][0]};
}
int lca() {
  int x = *w.begin();
  if (get(x) == 1) return x;
  for (int i = 19; i > -1; i--) {
    if (par[x][i] && get(par[x][i]) == 2) {
      x = par[x][i];
    }
  }
  return par[x][0];
}
int add(int x) {
  int k = get(x);
  int ans = 0;
  if (cur.size() == 0 || k == 2) return 0;
  if (k == 0) {
    pair<int, int> p = solve1(x);
    return p.first + add(p.second);
  }
  int y = lca();
  ans += t[y] - t[x];
  return ans;
}
int k;
bool check(int x) {
  int ans = 0;
  w.clear();
  cur.clear();
  for (int i = 1; i <= x; i++) {
    ans += add(i);
    w.insert(i);
    cur.insert(st[i]);
  }
  if (ans < k) return 1;
  for (int i = x + 1; i <= n; i++) {
    w.erase(i - x);
    cur.erase(st[i - x]);
    ans -= add(i - x);
    ans += add(i);
    w.insert(i);
    cur.insert(st[i]);
    if (ans < k) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &k);
  int x, y, z;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  if (n == k) return cout << n, 0;
  dfs(1, 0, 0);
  int l = 1, r = n;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l;
}
