#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = 1e9 + 19;
const int K = 20;
int n, k;
int jump[N][K];
vector<int> e[N];
int tin[N];
int tout[N];
bool use[N];
int h[N];
int rev[N];
int tmr;
void read() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    e[v].push_back(u);
    e[u].push_back(v);
  }
}
void dfs(int v, int hh) {
  use[v] = 1;
  tin[v] = tmr++;
  h[v] = hh;
  for (auto u : e[v])
    if (!use[u]) {
      dfs(u, hh + 1);
      jump[u][0] = v;
    }
  tout[v] = tmr;
}
bool isPar(int v, int u) { return tin[v] <= tin[u] && tout[u] <= tout[v]; }
int getLCA(int v, int u) {
  if (isPar(v, u)) return v;
  if (isPar(u, v)) return u;
  for (int t = K - 1; t >= 0; t--)
    if (!isPar(jump[v][t], u)) v = jump[v][t];
  return jump[v][0];
}
void solve() {
  dfs(0, 0);
  jump[0][0] = 0;
  for (int i = 1; i < K; i++)
    for (int v = 0; v < n; v++) jump[v][i] = jump[jump[v][i - 1]][i - 1];
  int answer = 0;
  int cnt = 0;
  set<int> q;
  for (int i = 0; i < n; i++) rev[tin[i]] = i;
  int r = 0;
  int head = -1;
  for (int l = 0; l < n; l++) {
    if (l == r) {
      assert(q.empty());
      q.insert(tin[l]);
      cnt = 1;
      head = l;
      r++;
    }
    for (; r < n;) {
      vector<int> nei;
      auto it = q.lower_bound(tin[r]);
      if (it != q.end()) nei.push_back(*it);
      if (it != q.begin()) nei.push_back(*(--it));
      int bestLCA = -1;
      for (auto t : nei) {
        int o = getLCA(rev[t], r);
        if (bestLCA == -1 || h[o] > h[bestLCA]) {
          bestLCA = o;
        }
      }
      int need;
      if (h[bestLCA] >= h[head]) {
        need = h[r] - h[bestLCA];
      } else {
        need = h[r] - h[bestLCA] + h[head] - h[bestLCA];
      }
      assert(need >= 0);
      if (cnt + need <= k) {
        q.insert(tin[r]);
        cnt += need;
        r++;
        if (h[bestLCA] < h[head]) head = bestLCA;
      } else
        break;
    }
    answer = max(answer, r - l);
    vector<int> nei;
    q.erase(tin[l]);
    auto it = q.lower_bound(tin[l]);
    if (it != q.end()) nei.push_back(*it);
    if (it != q.begin()) nei.push_back(*(--it));
    int bestLCA = -1;
    for (auto t : nei) {
      int o = getLCA(rev[t], l);
      if (bestLCA == -1 || h[o] > h[bestLCA]) {
        bestLCA = o;
      }
    }
    assert(h[l] >= h[bestLCA]);
    cnt -= h[l] - h[bestLCA];
    if (q.empty()) {
      cnt = 0;
      head = -1;
    } else {
      int v = *q.begin();
      int u = *q.rbegin();
      int o = getLCA(rev[v], rev[u]);
      if (h[o] > h[head]) {
        cnt -= h[o] - h[head];
        head = o;
      }
    }
  }
  printf("%d\n", answer);
}
void stress() {}
int main() {
  if (1) {
    int k = 1;
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
    }
  } else {
    stress();
  }
  return 0;
}
