#include<bits/stdc++.h>
using namespace std;
  
  class graph{
  public:
    map<int,vector<int>> map1;
    void edges(int a,int b){
        map1[a].push_back(b);
    }
    void tour_helper(int n,map<int,bool> &visited,int &count){
        visited[n]=true;
        for(auto it:map1[n]){
            if(visited[it]==false){
                count++;
                tour_helper(it,visited,count);
            }
        }
    }
    void tour(int n){
        map<int,bool> visited;
        for(auto it:map1)
            visited[it.first]=false;

        int ans=0;
        for(auto it:map1){
            tour_helper(it.first,visited,ans);
            for(auto it:map1)
                visited[it.first]=false;

        }

        cout<<ans+n<<endl;
     }
  };
int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    graph g;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        g.edges(a,b);
    }
    g.tour(n);

}
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

long long N, K;
long long A[1 << 18], B[1 << 18];

bool used[1 << 18];
bool forced[1 << 18];
long long dp[1 << 18];
vector<int> X[1 << 18];

void dfs(int pos, int border) {
	used[pos] = true;

	vector<long long> vec;
	for (int i : X[pos]) {
		if (used[i] == true) continue;
		dfs(i, border);
		vec.push_back(dp[i] + 1);
	}
	sort(vec.begin(), vec.end());

	if (vec.size() == 0) {
		dp[pos] = 0;
		return;
	}
	
	if (vec[0] + vec[vec.size() - 1] <= -1) {
		dp[pos] = vec[0];
		return;
	}
	else if (vec[vec.size() - 1] == border) {
		forced[pos] = true;
		dp[pos] = -(border + 1);
		return;
	}
	else {
		dp[pos] = vec[vec.size() - 1];
		return;
	}
}

bool solve(int border) {
	for (int i = 1; i <= N; i++) dp[i] = 0;
	for (int i = 1; i <= N; i++) used[i] = false;
	for (int i = 1; i <= N; i++) forced[i] = false;
	dfs(1, border);
	
	int cnts = 0;
	if (dp[1] >= 0 || forced[1] == true) cnts++;
	for (int i = 2; i <= N; i++) {
		if (forced[i] == true) cnts++;
	}
	if (cnts > K) return false;
	return true;
}

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N - 1; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}

	long long cl = 1, cr = N + 1, cm, minx = (1 << 30);
	for (int i = 0; i < 22; i++) {
		cm = (cl + cr) / 2;
		bool I = solve(cm);
		if (I == true) { cr = cm; minx = min(minx, cm); }
		else { cl = cm; }
	}
	cout << minx << endl;
	return 0;
}