#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

const int N = 4e5 + 5, mod = 1e9 + 7;

vector<int> adj[N];
int in[N];

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        in[u]++;
        in[v]++;
    }
    queue<int> q;
    for(int i = 1; i < N; i++){
        if(in[i] == 1){
            q.push(i);
        }
    }
    int ans = 0;
    while(q.size()){
        int node = q.front();
        q.pop();
        if(in[node] == 0) continue;
        ans++;
        for(auto i: adj[node]) {
            in[i]--;
            if (in[i] == 1) {
                q.push(i);
            }
        }
    }
    for(int i = 1; i < N; i++){
        ans += (in[i] > 1);
    }
    cout << ans;

    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 200005, inf = 0x3f3f3f3f;
int n, k;
vector<int> G[N];
int l[N], z1, Q;
int dis[N], dp[N], far[N];
void add_edge(int x, int y)
{
	G[x].push_back(y);
}

void dfs(int x, int f, int d)
{
	l[x] = d;
	for (int i = 0; i < sz(G[x]); ++i)
	{
		int to = G[x][i];
		if (to == f) continue;
		dfs(to, x, d + 1);
	}
}

void init()
{
	read(n); read(k);
	for (int i = 1, v, u; i < n; ++i)
	{
		read(u); read(v);
		add_edge(u, v);
		add_edge(v, u);
	}
	dfs(1, 0, 0);
	int mx = 0;
	for (int i = 1; i <= n; ++i) if (checkmax(mx, l[i])) z1 = i;
}

void run(int x, int f)
{
	dp[x] = 0; far[x] = -inf; dis[x] = inf;
	int child = 0;
	for (int i = 0; i < sz(G[x]); ++i)
	{
		int to = G[x][i];
		if (to == f) continue;
		++child;
		run(to, x);
		checkmin(dis[x], dis[to] + 1);
		dp[x] += dp[to];
	}
	if (child == 0)
	{
		dp[x] = far[x] = 0;
		dis[x] = inf;
	}
	else
	{
		for (int i = 0; i < sz(G[x]); ++i)
		{
			int to = G[x][i];
			if (to == f) continue;
			if (Q < dis[x] + far[to] + 1) checkmax(far[x], far[to] + 1);
		}
		//out(x); out(far[x]); outln(dis[x]);
		if (far[x] == Q || dis[x] == Q + Q + 1)
		{
			++dp[x];
			dis[x] = 0; far[x] = -inf;
		}
	}
	//out(Q); out(x); out(dp[x]); out(dis[x]); outln(far[x]);
}

bool check(int mid)
{
	Q = mid;
	run(z1, 0);
	if (dis[z1] > Q) ++dp[z1];
	if (dp[z1] <= k) return 1;
	else return 0;
}

void solve()
{
	int l = 1, r = n - 1, mid, best = n - 1;
	while (l <= r)
	{
		mid = (l + r) >> 1;
		if (check(mid)) best = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", best);
}

int main()
{
	//setIO("");
	init();
	solve();
	return 0;
}

