#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool f = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = 1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return f ? -x : x;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
void writep(long long x) {
  write(x);
  putchar(' ');
}
const int N = 1e5 + 5;
int n, m, head[N], opt, sum, fa[20][N], dfn[N], dep[N], id[N], cnt;
struct info {
  int to, nxt;
} e[N << 1];
void add(int x, int y) {
  e[++opt] = (info){y, head[x]};
  head[x] = opt;
  e[++opt] = (info){x, head[y]};
  head[y] = opt;
}
void dfs(int u) {
  dep[u] = dep[fa[0][u]] + 1;
  dfn[u] = ++cnt;
  id[cnt] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    int k = e[i].to;
    if (k == fa[0][u]) continue;
    fa[0][k] = u;
    dfs(k);
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = (int)(18); i >= (int)(0); i--)
    if (dep[fa[i][x]] >= dep[y]) x = fa[i][x];
  if (x == y) return x;
  for (int i = (int)(18); i >= (int)(0); i--) {
    if (fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y];
  }
  return fa[0][x];
}
int dis(int x, int y) {
  x = id[x];
  y = id[y];
  return dep[x] + dep[y] - 2 * dep[lca(x, y)];
}
set<int> s;
set<int>::iterator it, wz;
void upd(int x, int op) {
  it = s.find(x);
  if (it == s.begin()) {
    it++;
    sum += op * (dis(x, *it) + dis(x, *--s.end()) - dis(*it, *--s.end()));
  } else if (it == --s.end()) {
    it--;
    sum += op * (dis(x, *it) + dis(x, *s.begin()) - dis(*it, *s.begin()));
  } else {
    wz = it;
    wz--;
    it++;
    sum += op * (dis(x, *wz) + dis(x, *it) - dis(*wz, *it));
  }
}
bool check(int md) {
  s.clear();
  sum = 0;
  for (int i = (int)(1); i <= (int)(md - 1); i++) {
    s.insert(dfn[i]);
    if (s.size() == 1) continue;
    upd(dfn[i], 1);
  }
  for (int i = (int)(md); i <= (int)(n); i++) {
    s.insert(dfn[i]);
    if (s.size() > 1) upd(dfn[i], 1);
    if (sum <= (m - 1) * 2) return 1;
    if (s.size() > 1) upd(dfn[i - md + 1], -1);
    s.erase(dfn[i - md + 1]);
  }
  return 0;
}
int main() {
  n = read();
  m = read();
  for (int i = (int)(1); i <= (int)(n - 1); i++) add(read(), read());
  dfs(1);
  for (int i = (int)(1); i <= (int)(18); i++)
    for (int j = (int)(1); j <= (int)(n); j++) {
      fa[i][j] = fa[i - 1][fa[i - 1][j]];
    }
  int l = 1, r = m, mid, ans = 0;
  while (l <= r) check(mid = l + r >> 1) ? l = (ans = mid) + 1 : r = mid - 1;
  cout << ans;
}
