#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, kk, dep[N], dp[N][20], id[N], mp[N], idx;
vector<int> v[N];
void dfs(int pos, int fa) {
  dep[pos] = dep[fa] + 1;
  dp[pos][0] = fa;
  id[pos] = ++idx;
  mp[idx] = pos;
  for (int i = 1; i < 20; i++) dp[pos][i] = dp[dp[pos][i - 1]][i - 1];
  for (auto &i : v[pos])
    if (i != fa) dfs(i, pos);
}
int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = 19; i >= 0; --i)
    if (dep[dp[a][i]] >= dep[b]) a = dp[a][i];
  if (a == b) return a;
  for (int i = 19; i >= 0; --i)
    if (dp[a][i] != dp[b][i]) a = dp[a][i], b = dp[b][i];
  return dp[a][0];
}
inline int dis(int a, int b) { return dep[a] + dep[b] - dep[lca(a, b)] * 2; }
set<int> s;
int modify(int pos, bool op) {
  if (!op) s.erase(id[pos]);
  if (!s.size()) {
    if (op) s.insert(id[pos]);
    return 1;
  }
  auto it = s.upper_bound(id[pos]), cpy = it;
  int pre = it == s.begin() ? mp[*s.rbegin()] : mp[*--cpy],
      nxt = it == s.end() ? mp[*s.begin()] : mp[*it];
  if (op) s.insert(id[pos]);
  return (dis(pre, pos) + dis(nxt, pos) - dis(pre, nxt)) / 2;
}
bool check(int mid) {
  s.clear();
  int cur = 0;
  for (int i = 1; i < mid; i++) cur += modify(i, 1);
  for (int i = mid; i <= n; i++) {
    cur += modify(i, 1);
    if (cur <= kk) return 1;
    cur -= modify(i - mid + 1, 0);
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> kk;
  int t1, t2;
  for (int i = 1; i < n; i++) {
    cin >> t1 >> t2;
    v[t1].push_back(t2);
    v[t2].push_back(t1);
  }
  dfs(1, 0);
  int l = 1, r = n, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
