#include <bits/stdc++.h>
using namespace std;
int N, M, D[110000], dad[110000][20], seg[110000 * 5], old;
int F[110000], cnt, B[110000], E[110000];
int sum = 0;
vector<int> v[110000];
void init(int x, int parent, int depth) {
  dad[x][0] = parent;
  D[x] = depth;
  B[x] = ++cnt;
  for (int i = 1; i <= 18; i++) dad[x][i] = dad[dad[x][i - 1]][i - 1];
  for (int i = 0; i < (int)v[x].size(); i++)
    if (v[x][i] != parent) init(v[x][i], x, depth + 1);
  E[x] = cnt;
}
int get_lca(int a, int b) {
  if (a == -1) return b;
  if (b == -1) return a;
  if (D[b] > D[a]) swap(a, b);
  for (int i = 18; i >= 0; i--)
    if (D[dad[a][i]] >= D[b]) a = dad[a][i];
  if (a == b) return a;
  for (int i = 18; i >= 0; i--)
    if (dad[a][i] != dad[b][i]) a = dad[a][i], b = dad[b][i];
  return dad[a][0];
}
int build(int k, int b, int e) {
  if (b == e) return seg[k] = b;
  return seg[k] = get_lca(build(2 * k, b, ((b + e) / 2)),
                          build(2 * k + 1, ((b + e) / 2) + 1, e));
}
int find(int k, int b, int e, int a1, int a2) {
  if (b > a2 || e < a1) return -1;
  if (a1 <= b && e <= a2) return seg[k];
  return get_lca(find(2 * k, b, ((b + e) / 2), a1, a2),
                 find(2 * k + 1, ((b + e) / 2) + 1, e, a1, a2));
}
int check(int l, int r) {
  int lca = get_lca(r, old);
  int sm = 0, len = 0;
  for (int i = E[r]; i; i -= (i & -i)) sm += F[i];
  for (int i = B[r] - 1; i; i -= (i & -i)) sm -= F[i];
  if (lca != old) {
    len = D[r] + D[old] - 2 * D[lca];
    if (sum + len <= M) old = lca;
  } else if (!sm) {
    int x = r;
    for (int j = 18; j >= 0; j--) {
      int y = dad[x][j];
      sm = 0;
      for (int i = E[y]; i; i -= (i & -i)) sm += F[i];
      if (B[y] - 1 >= 0)
        for (int i = B[y] - 1; i; i -= (i & -i)) sm -= F[i];
      if (!sm && y) {
        x = dad[x][j], len += (1 << j);
      }
    }
    len++;
  }
  if (sum + len <= M) {
    sum += len;
    return 1;
  }
  return 0;
}
void remove(int x, int y) {
  for (int i = B[x]; i <= N; i += (i & -i)) F[i]--;
  if (x == y) return;
  int lca = find(1, 1, N, x + 1, y);
  int sm = 0, len = 0;
  for (int i = E[x]; i; i -= (i & -i)) sm += F[i];
  for (int i = B[x] - 1; i; i -= (i & -i)) sm -= F[i];
  if (lca != old) {
    sum -= D[x] + D[lca] - 2 * D[old];
    old = lca;
  } else if (!sm) {
    int t = x;
    for (int j = 18; j >= 0; j--) {
      int y = dad[t][j];
      sm = 0;
      for (int i = E[y]; i; i -= (i & -i)) sm += F[i];
      if (B[y] - 1 >= 0)
        for (int i = B[y] - 1; i; i -= (i & -i)) sm -= F[i];
      if (y && !sm) t = dad[t][j], len += (1 << j);
    }
    sum -= len + 1;
  }
}
int main() {
  cin >> N >> M;
  for (int i = 1, a, b; i < N; i++) {
    scanf(" %d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  init(1, 0, 1);
  build(1, 1, N);
  int res = 0;
  old = 1;
  for (int i = 1, ptr = 0; i <= N; i++) {
    if (i - 1) remove(i - 1, ptr);
    if (ptr < i) {
      ptr = i;
      sum = 1;
      old = i;
      for (int j = B[i]; j <= N; j += (j & -j)) F[j]++;
    }
    while (ptr < N && check(i, ptr + 1)) {
      ptr++;
      for (int j = B[ptr]; j <= N; j += (j & -j)) F[j]++;
    }
    res = max(res, ptr - i + 1);
  }
  cout << res << endl;
  return 0;
}
