#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, k, lg;
int pre[N], post[N], prenum;
int p[20][N], lv[N];
int f[N];
vector<int> adj[N];
inline int preorder(int u, int par = 0) {
  post[u] = pre[u] = ++prenum;
  lv[u] = lv[par] + 1;
  p[0][u] = par;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != par) post[u] = max(post[u], preorder(v, u));
  }
  return post[u];
}
inline int get(int u) {
  int ret = 0;
  for (int i = post[u]; i > 0; i -= i & -i) ret += f[i];
  for (int i = pre[u] - 1; i > 0; i -= i & -i) ret -= f[i];
  return ret;
}
inline void update(int u, int lca, int val = 1) {
  for (int i = pre[u]; i > 0 && i <= n; i += i & -i) f[i] += val;
  for (int i = pre[p[0][lca]]; i > 0 && i <= n; i += i & -i) f[i] -= val;
}
inline int getlca(int u, int v) {
  if (lv[v] > lv[u]) return getlca(v, u);
  for (int k = lg; k >= 0; k--)
    if (lv[p[k][u]] >= lv[v]) u = p[k][u];
  if (u == v) return u;
  for (int k = lg; k >= 0; k--)
    if (p[k][u] != p[k][v]) u = p[k][u], v = p[k][v];
  return p[0][u];
}
inline int findlast(int u, int lim, int val = 0) {
  for (int k = lg; k >= 0; k--)
    if (lv[p[k][u]] >= lv[lim] && get(p[k][u]) <= val) u = p[k][u];
  return u;
}
inline bool can(int m) {
  memset(f + 1, 0, n * sizeof f[0]);
  int cnt = 0;
  int lca = getlca(1, 2);
  update(1, lca);
  cnt += lv[1] - lv[lca] + 1;
  update(2, lca);
  cnt += lv[2] - lv[lca];
  if (m == 2 && cnt <= k) return true;
  for (int i = 3; i <= n; i++) {
    int nlca = getlca(lca, i);
    update(p[0][lca], nlca, get(lca));
    cnt += lv[lca] - lv[nlca];
    if (get(i) == 0) {
      int tmp = findlast(i, nlca);
      cnt += lv[i] - lv[tmp] + 1;
    }
    update(i, nlca);
    lca = nlca;
    if (i > m) {
      int u = i - m;
      update(u, lca, -1);
      if (get(u) == 0 || lca == u) {
        int tmp = findlast(u, lca);
        if (lca != u) cnt -= lv[u] - lv[tmp] + 1;
        if (p[0][tmp] == lca || lca == u) {
          int nlca =
              get(u + 1) == m ? u + 1 : p[0][findlast(u + 1, lca, m - 1)];
          if (nlca != lca) update(p[0][nlca], lca, -m);
          cnt -= lv[nlca] - lv[lca];
          lca = nlca;
        }
      }
    }
    if (i >= m && cnt <= k) return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &k);
  for (lg = 1; 1 << lg < n; lg++)
    ;
  lg--;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  preorder(1);
  for (int k = 1; k <= lg; k++)
    for (int i = 1; i <= n; i++) p[k][i] = p[k - 1][p[k - 1][i]];
  int lo = 2, hi = n;
  while (lo <= hi) {
    int mid = lo + hi >> 1;
    if (can(mid))
      lo = mid + 1;
    else
      hi = mid - 1;
  }
  printf("%d\n", hi);
}
