#include <bits/stdc++.h>
using namespace std;
int tu(int val) { return (1 << val); }
bool iset(int mask, int id) {
  if ((mask & tu(id)) != 0) return true;
  return false;
}
void doset(int &mask, int id) { mask |= tu(id); }
void dounset(int &mask, int id) { mask = mask & (~tu(id)); }
template <typename T>
string tos(T a) {
  stringstream ss;
  string ret;
  ss << a;
  ss >> ret;
  return ret;
}
const int lim = 200007, lgN = 20;
int n, k;
namespace TR {
struct edge {
 public:
  int t, w;
  edge(int _t, int _w) {
    t = _t;
    w = _w;
  }
};
vector<edge> e[lim];
vector<int> dfsList;
int pre[lim][lgN], dep[lim];
void link(int a, int b, int w) {
  e[a].push_back(edge(b, w));
  e[b].push_back(edge(a, w));
}
void dfs(int u, int p, int w) {
  dfsList.push_back(u);
  pre[u][0] = p;
  for (int(i) = (1); (i) < (lgN); (i)++) pre[u][i] = pre[pre[u][i - 1]][i - 1];
  dep[u] = dep[p] + w;
  for (int(i) = (0); (i) < (e[u].size()); (i)++) {
    int v = e[u][i].t;
    int ws = e[u][i].w;
    if (v == p) continue;
    dfs(v, u, ws);
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = lgN - 1; i >= 0; i--) {
    if (dep[pre[u][i]] >= dep[v]) u = pre[u][i];
  }
  if (u == v) return u;
  for (int i = lgN - 1; i >= 0; i--) {
    if (pre[u][i] != pre[v][i]) u = pre[u][i], v = pre[v][i];
  }
  return pre[u][0];
}
int query(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int z = lca(u, v);
  if (z == v)
    return dep[u] - dep[z];
  else
    return dep[v] + dep[u] - 2 * dep[z];
}
}  // namespace TR
namespace F {
int prior[lim], cur_res;
struct cusComp {
  bool operator()(int a, int b) { return prior[a] < prior[b]; }
};
set<int, cusComp> l;
set<int, cusComp>::iterator prev(const set<int, cusComp>::iterator t) {
  set<int, cusComp>::iterator ret = t;
  return --ret;
}
set<int, cusComp>::iterator next(const set<int, cusComp>::iterator t) {
  set<int, cusComp>::iterator ret = t;
  return ++ret;
}
void add(int x) {
  if (l.empty()) {
    l.insert(x);
    return;
  } else if (l.size() == 1) {
    cur_res = TR::query(*l.begin(), x) * 2;
    l.insert(x);
    return;
  }
  set<int, cusComp>::iterator isuc = l.upper_bound(x), ipre;
  if (isuc == l.begin() || isuc == l.end())
    ipre = l.begin(), isuc = prev(l.end());
  else
    ipre = prev(isuc);
  cur_res = cur_res - TR::query(*isuc, *ipre) + TR::query(x, *ipre) +
            TR::query(x, *isuc);
  l.insert(x);
}
void remove(int x) {
  if (l.size() <= 2) {
    cur_res = 0;
    l.erase(x);
    return;
  }
  set<int, cusComp>::iterator icur = l.find(x), isuc, ipre;
  if (next(icur) == l.end())
    isuc = l.begin(), ipre = prev(icur);
  else if (icur == l.begin())
    ipre = next(icur), isuc = prev(l.end());
  else
    isuc = next(icur), ipre = prev(icur);
  cur_res = cur_res + TR::query(*isuc, *ipre) - TR::query(x, *ipre) -
            TR::query(x, *isuc);
  l.erase(x);
}
void init() {
  TR::dfs(1, 0, 0);
  int vl = 0;
  for (typeof(TR::dfsList.begin()) it = TR::dfsList.begin();
       it != TR::dfsList.end(); it++) {
    prior[*it] = ++vl;
  }
}
}  // namespace F
void print_res(int res) { printf("%d\n", res); }
int main() {
  cin >> n >> k;
  for (int(i) = (1); (i) < (n); (i)++) {
    int va, vb;
    cin >> va >> vb;
    TR::link(va, vb, 1);
  }
  F::init();
  F::add(1);
  int res = 0;
  for (int i = 1, j = 1; i <= n; ++i) {
    for (++j; j <= n; ++j) {
      F::add(j);
      if ((F::cur_res >> 1) + 1 > k) {
        F::remove(j);
        break;
      }
    }
    res = max(res, j - i);
    --j;
    F::remove(i);
  }
  print_res(res);
  return 0;
}
