#include <bits/stdc++.h>
using namespace std;
struct node {
  int mn, mncnt, mx, mxcnt;
} f[400005];
int hldnum[100005], hldroot[100005], chain[100005],
    chainNum = 1, n, k, a, b, par[100005], hldtme, sub[100005], lz[400005];
vector<int> v[100005];
int dfs(int x, int y) {
  sub[x] = 1;
  for (int i = 0; i < v[x].size(); ++i)
    if (v[x][i] != y) sub[x] += dfs(v[x][i], x);
  return sub[x];
}
void hld(int x, int y) {
  chain[x] = chainNum;
  hldnum[x] = ++hldtme;
  par[x] = y;
  int mx = 0;
  for (int i = 0; i < v[x].size(); ++i)
    if (v[x][i] != y && sub[v[x][i]] > sub[mx]) mx = v[x][i];
  if (mx) hld(mx, x);
  for (int i = 0; i < v[x].size(); ++i)
    if (v[x][i] != y && v[x][i] != mx) {
      ++chainNum;
      hldroot[chainNum] = v[x][i];
      hld(v[x][i], x);
    }
}
void upd_lazy(int x, int l, int r) {
  f[x].mx += lz[x];
  f[x].mn += lz[x];
  if (l != r) {
    lz[x * 2] += lz[x];
    lz[x * 2 + 1] += lz[x];
  }
  lz[x] = 0;
}
void merge(node &x, node l, node r) {
  x.mncnt = x.mxcnt = 0;
  x.mx = max(l.mx, r.mx);
  x.mn = min(l.mn, r.mn);
  if (l.mn == x.mn) x.mncnt += l.mncnt;
  if (r.mn == x.mn) x.mncnt += r.mncnt;
  if (l.mx == x.mx) x.mxcnt += l.mxcnt;
  if (r.mx == x.mx) x.mxcnt += r.mxcnt;
}
void build(int x, int l, int r) {
  if (l == r) {
    f[x].mxcnt = f[x].mncnt = 1;
    return;
  }
  int md = (l + r) / 2;
  build(x * 2, l, md);
  build(x * 2 + 1, md + 1, r);
  merge(f[x], f[x * 2], f[x * 2 + 1]);
}
void upd(int x, int l, int r, int ll, int rr, int v) {
  upd_lazy(x, l, r);
  if (l > rr || r < ll) return;
  if (l >= ll && r <= rr) {
    lz[x] = v;
    upd_lazy(x, l, r);
    return;
  }
  int md = (l + r) / 2;
  upd(x * 2, l, md, ll, rr, v);
  upd(x * 2 + 1, md + 1, r, ll, rr, v);
  merge(f[x], f[x * 2], f[x * 2 + 1]);
}
void upd2(int x, int v) {
  while (x) {
    upd(1, 1, n, hldnum[hldroot[chain[x]]], hldnum[x], v);
    x = par[hldroot[chain[x]]];
  }
}
int calc() {
  if (f[1].mx == 0) return 0;
  int dec = f[1].mncnt * (f[1].mn == 0);
  int dec2 = f[1].mxcnt * (f[1].mx != 0);
  return n + 1 - dec - dec2;
}
bool add(int x) {
  upd2(x, 1);
  bool ok = (calc() <= k);
  upd2(x, -1);
  return ok;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, 0);
  build(1, 1, n);
  hldroot[1] = 1;
  hld(1, 0);
  int ans = 0, i = 1, j = 1;
  while (j <= n) {
    while (j <= n && add(j)) {
      upd2(j, 1);
      ++j;
    }
    ans = max(ans, j - i);
    upd2(i, -1);
    ++i;
  }
  cout << ans << '\n';
}
