#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 5757;
const long long Linf = (long long)1e18 + 5757;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T lcm(T a, T b) {
  return a / __gcd(a, b) * b;
}
inline int read() {
  int x;
  scanf(" %d", &x);
  return x;
}
const int N = 101010;
const int LG = 20;
int n, k;
vector<int> G[N];
int anc[N][LG + 1];
int tin[N], tout[N], ptr = 0;
int depth[N];
void dfs(int u, int p) {
  depth[u] = depth[p] + 1;
  anc[u][0] = p;
  for (int i = 1; i <= LG; i++) anc[u][i] = anc[anc[u][i - 1]][i - 1];
  tin[u] = ++ptr;
  for (__typeof(G[u].begin()) it = G[u].begin(); it != G[u].end(); it++) {
    int v = *it;
    if (v != p) {
      dfs(v, u);
    }
  }
  tout[u] = ptr;
}
int jump(int u, int d) {
  for (int i = LG; i >= 0; i--)
    if ((1 << i) <= d) {
      d -= (1 << i);
      u = anc[u][i];
    }
  return u;
}
int get_lca(int u, int v) {
  if (!u || !v) return u + v;
  if (depth[u] > depth[v]) u = jump(u, depth[u] - depth[v]);
  if (depth[v] > depth[u]) v = jump(v, depth[v] - depth[u]);
  if (u == v) return u;
  for (int i = LG; i >= 0; i--) {
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  }
  return anc[u][0];
}
int tree[N * 5];
void build(int k, int b, int e) {
  if (b == e)
    tree[k] = b;
  else {
    build(k + k, b, (b + e) / 2);
    build(k + k + 1, (b + e) / 2 + 1, e);
    tree[k] = get_lca(tree[k + k], tree[k + k + 1]);
  }
}
int range_lca(int k, int b, int e, int x1, int x2) {
  if (b > x2 || e < x1) return 0;
  if (b >= x1 && e <= x2) return tree[k];
  return get_lca(range_lca(k + k, b, (b + e) / 2, x1, x2),
                 range_lca(k + k + 1, (b + e) / 2 + 1, e, x1, x2));
}
int f[N];
void init() {
  for (int i = 0; i < N; i++) f[i] = 0;
}
void put(int x, int by) {
  while (x < N) {
    f[x] += by;
    x += x & -x;
  }
}
int get(int x) {
  int res = 0;
  while (x > 0) {
    res += f[x];
    x -= x & -x;
  }
  return res;
}
int get(int l, int r) { return get(r) - get(l - 1); }
int size, root;
void insert(int u) {
  if (size == 0) {
    root = u;
    size = 1;
    put(tin[u], +1);
    return;
  }
  int lca = get_lca(root, u);
  if (lca != root) {
    size += depth[u] + depth[root] - 2 * depth[lca];
    root = lca;
  } else if (get(tin[u], tout[u]) == 0) {
    int x = u;
    for (int i = LG; i >= 0; i--) {
      int v = anc[x][i];
      if (v > 0 && get(tin[v], tout[v]) == 0) {
        x = v;
        size += (1 << i);
      }
    }
    ++size;
  }
  put(tin[u], +1);
}
void remove(int u, int l, int r) {
  if (size == 1) {
    size = 0;
    return;
  }
  put(tin[u], -1);
  int nroot = range_lca(1, 1, n, l, r);
  if (nroot != root) {
    if (nroot == root) return;
    size -= depth[nroot] + depth[u] - 2 * depth[root];
    root = nroot;
    ;
    return;
  }
  if (get(tin[u], tout[u]) == 0) {
    int x = u;
    for (int i = LG; i >= 0; i--) {
      int v = anc[x][i];
      if (v > 0 && get(tin[v], tout[v]) == 0) {
        x = v;
        size -= (1 << i);
      }
    }
    --size;
    assert(size >= 0);
  }
}
bool can(int len) {
  init();
  size = 0;
  for (int i = 1; i < len; i++) insert(i);
  for (int i = len; i <= n; i++) {
    insert(i);
    if (i > len) remove(i - len, i - len + 1, i);
    ;
    if (size <= k) return true;
  }
  return false;
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  build(1, 1, n);
  int l = 0, r = k + 1;
  while (l + 1 < r) {
    int m = (l + r) >> 1;
    if (can(m))
      l = m;
    else
      r = m;
  }
  printf("%d\n", l);
  return 0;
}
