#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
  ios::sync_with_stdio(false);
  run();
}
vector<int> child[100000];
int up[100000][20];
int hld[100000];
int size[100000];
int depth[100000];
int height[100000];
int pref[100000];
int p[100000];
vector<int> hld_fen[100000];
void prepare(int x) {
  p[0] = -1;
  size[x] = 1, pref[x] = -1;
  for (auto y : child[x]) {
    child[y].erase(find(child[y].begin(), child[y].end(), x));
    depth[y] = depth[x] + 1;
    up[y][0] = x;
    for (int i = 0; i < 19; i++) up[y][i + 1] = up[up[y][i]][i];
    p[y] = x;
    prepare(y);
    size[x] += size[y];
    if (pref[x] == -1 or size[y] > size[pref[x]]) pref[x] = y;
  }
}
void init_hld(int x, int dent = 0) {
  for (auto y : child[x]) {
    if (y == pref[x])
      hld[y] = hld[x];
    else
      hld[y] = y;
    init_hld(y);
    if (y == pref[x]) height[x] = height[y] + 1;
  }
  if (hld[x] == x) hld_fen[x].resize(height[x] + 1);
}
int card = 0;
int idx_lef = 0;
int idx_rgt = 0;
int active = 0;
int sum_to_root = 0;
int fen_get(vector<int> &v, int x) {
  int res = 0;
  for (int i = x; i >= 0; --(i &= i + 1)) res += v[i];
  return res;
}
void fen_add(vector<int> &v, int x, int y) {
  for (int i = x; i < v.size(); i |= i + 1) v[i] += y;
}
int v_get(int x) {
  auto &fen = hld_fen[hld[x]];
  return fen_get(fen, height[x]);
}
void v_add(int x, int by) {
  auto &fen = hld_fen[hld[x]];
  fen_add(fen, height[x], by);
}
int get_footprint(int x) {
  if (v_get(x)) return 0;
  int y = x;
  for (int rad = 20; rad--;) {
    int mid = up[y][rad];
    if (v_get(mid) == 0) y = mid;
  }
  return 1 + (depth[x] - depth[y]);
}
int get_stem(int x) {
  int y = x;
  for (int rad = 20; rad--;) {
    int mid = up[y][rad];
    if (v_get(mid) < active) y = mid;
  }
  return max(0, depth[y] - 1);
}
void insert(int x) {
  card += get_footprint(x);
  ++active;
  for (int i = x; ~i; i = p[hld[i]]) {
    auto &fen = hld_fen[hld[i]];
    fen_add(fen, height[i], +1);
  }
}
void remove(int x) {
  for (int i = x; ~i; i = p[hld[i]]) {
    auto &fen = hld_fen[hld[i]];
    fen_add(fen, height[i], -1);
  }
  --active;
  card -= get_footprint(x);
}
int real_card() {
  if (active <= 1) return active;
  return card - (idx_lef < idx_rgt ? get_stem(idx_lef) : 0);
}
void run() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    child[a].push_back(b);
    child[b].push_back(a);
  }
  prepare(0), init_hld(0);
  int res = 0;
  while (idx_lef < n) {
    int c = real_card();
    if (c <= k) res = max(res, idx_rgt - idx_lef);
    if (c <= k and idx_rgt < n) {
      insert(idx_rgt++);
    } else {
      remove(idx_lef++);
    }
  }
  cout << res << endl;
}
