#include "bits/stdc++.h"
#define pb push_back

using namespace std;

using ll = long long;
const ll N = 2e3 + 5;

vector<ll>g[N];
bool vis[N];

void dfs(ll v){
    vis[v] = true;
    for(ll u : g[v]){
        if(!vis[u]){
            dfs(u);
        }
    }
}
signed main(){
    ll n,m;
    cin >> n >> m;

    for(ll i=0;i<m;i++){
        ll x,y;
        cin >> x >> y;

        g[x].pb(y);
    }

    ll ans = 0;

    for(ll i=1;i<=n;i++){
        memset(vis,false,sizeof(vis));
        dfs(i);

        ll cnt = 0;
        for(ll i=0;i<=n;i++){
            if(vis[i]){
                cnt++;
            }
        }

        ans = ans + cnt;
    }

    cout << ans << "\n";
    return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(2e5 + 10), INF(1e9);
std::vector<int> G[N];
int n, K, f[N], g[N], R, cnt;

void dfs(int x, int fa)
{
	f[x] = 0, g[x] = INF;
	for (auto i : G[x]) if (i != fa)
		dfs(i, x), f[x] = std::max(f[x], f[i] + 1), g[x] = std::min(g[x], g[i] + 1);
	if (f[x] + g[x] <= R) f[x] = -INF;
	if (f[x] == R) f[x] = -INF, g[x] = 0, ++cnt;
	if (x == 1 && f[x] >= 0) ++cnt;
}

int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read(), K = read();
	for (int i = 1, a, b; i < n; i++)
		a = read(), b = read(), G[a].push_back(b), G[b].push_back(a);
	int l = 1, r = n, ans = n;
	while (l <= r)
	{
		R = (l + r) >> 1, cnt = 0, dfs(1, 0);
		if (cnt <= K) ans = R, r = R - 1;
		else l = R + 1;
	}
	printf("%d\n", ans);
	return 0;
}
