#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 1e5 + 5;
const int LOG = 17;
int n, k, x, y, something_stupid, size, ans, mylog[N], dep[N], child[N],
    start[N], head[N], lca[LOG][N], rmq[LOG][N], fen[N];
vector<int> v[N];
int dfs(int root, int x, int t) {
  dep[x] = t;
  lca[0][x] = root;
  child[x] = 1;
  for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end(); it++)
    if (*it != root) child[x] += dfs(x, *it, t + 1);
  return child[x];
}
void dfs2(int root, int x, int head) {
  start[x] = ++something_stupid;
  ::head[x] = head;
  for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end(); it++)
    if (*it != root and child[*it] * 2 >= child[x]) dfs2(x, *it, head);
  for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end(); it++)
    if (*it != root and child[*it] * 2 < child[x]) dfs2(x, *it, *it);
}
int get(int x, int y) {
  if (!x or !y) return 0;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = LOG - 1; i >= 0; i--)
    if (dep[lca[i][x]] >= dep[y]) x = lca[i][x];
  if (x == y) return x;
  for (int i = LOG - 1; i >= 0; i--)
    if (lca[i][x] != lca[i][y]) {
      x = lca[i][x];
      y = lca[i][y];
    }
  return lca[0][x];
}
int qu(int x, int y) {
  if (x == y) return x;
  x++;
  int k = mylog[y - x + 1];
  int ans = get(rmq[k][x], rmq[k][y - (1 << k) + 1]);
  return ans;
}
void update(int x, int y, int k) {
  y++;
  for (; x < N; x += x & (-x)) fen[x] += k;
  for (; y < N; y += y & (-y)) fen[y] -= k;
}
int qu(int x) {
  int sum = 0;
  for (x = start[x]; x; x -= x & (-x)) sum += fen[x];
  return sum;
}
void up(int x, int k) {
  while (x) {
    update(start[head[x]], start[x], k);
    x = lca[0][head[x]];
  }
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 2; i <= n; i++) mylog[i] = mylog[i >> 1] + 1;
  for (int i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(0, 1, 1);
  dfs2(0, 1, 1);
  for (int i = 1; i <= LOG - 1; i++)
    for (int j = 1; j <= n; j++) lca[i][j] = lca[i - 1][lca[i - 1][j]];
  for (int i = 2; i <= n; i++) rmq[0][i] = get(i - 1, i);
  for (int i = 1; i <= LOG - 1; i++)
    for (int j = 1; j <= n; j++)
      rmq[i][j] = get(rmq[i - 1][j], rmq[i - 1][min(n, j + (1 << i - 1))]);
  size = 1;
  up(1, 1);
  int j = 2;
  for (int i = 1; i <= n; i++) {
    while (j <= n and size <= k) {
      ans = max(ans, j - i);
      int bef = qu(i, j - 1);
      int now = qu(i, j);
      if (bef != now) {
        size += dep[bef] + dep[j] - 2 * dep[now];
        up(lca[0][bef], qu(bef));
        up(j, 1);
        up(lca[0][now], -qu(bef) - 1);
      } else {
        int x = j;
        for (int i = LOG - 1; i >= 0; i--)
          if (dep[lca[i][x]] >= dep[bef] and !qu(lca[i][x])) x = lca[i][x];
        if (!qu(x)) size += dep[j] - dep[x] + 1;
        up(j, 1);
        up(lca[0][now], -1);
      }
      j++;
    }
    if (size <= k) {
      ans = max(ans, j - i);
      break;
    }
    if (i == n) break;
    int bef = qu(i, j - 1);
    int now = qu(i + 1, j - 1);
    up(i, -1);
    if (bef != now) {
      size -= dep[now] + dep[i] - 2 * dep[bef];
      up(lca[0][now], -qu(now));
      up(lca[0][bef], qu(now) + 1);
    } else {
      up(lca[0][now], 1);
      int x = i;
      for (int i = LOG - 1; i >= 0; i--)
        if (dep[lca[i][x]] >= dep[now] and !qu(lca[i][x])) x = lca[i][x];
      if (!qu(i)) size -= dep[i] - dep[x] + 1;
    }
    if (size <= k) ans = max(ans, j - i - 1);
  }
  cout << ans << '\n';
  return 0;
}
