#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,K,V;
vector<int> E[202020];

int need[202020],aff[202020];
int num;

void dfs(int cur,int pre) {
	need[cur]=0;
	aff[cur]=-1;
	
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		if(aff[e]>=0) aff[cur]=max(aff[cur],aff[e]-1);
		if(need[e]>=0) need[cur]=max(need[cur],need[e]+1);
	}
	
	if(aff[cur]>=need[cur]) {
		need[cur]=-1;
	}
	else {
		if(need[cur]>=V) {
			need[cur]=-1;
			aff[cur]=V;
			num++;
		}
		else {
			aff[cur]=-1;
		}
	}
	
	

}


int ok(int v) {
	if(v<=0) return 0;
	
	V=v;
	num=0;
	dfs(0,0);
	if(need[0]>=0) num++;
	return num<=K;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	int ret=N;
	for(j=20;j>=0;j--) if(ok(ret-(1<<j))) ret-=1<<j;
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;

#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(x) begin(x),end(x)
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl

struct fast_ios {
    fast_ios() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    };
} fast_ios_;

using ll = long long;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T>
bool chmax(T &a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v);
template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p);
template<class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &mp);

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '[';
    REP(i, v.size()) {
        if (i) os << ',';
        os << v[i];
    }
    return os << ']';
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << '(' << p.first << ' ' << p.second << ')';
}

template<class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
    os << '{';
    for (const auto &p : mp) {
        os << p << endl;
    }
    return os << '}';
}

const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();

template<class T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) :
            from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) :
            from(from), to(to), cost(cost) {}
};


int main() {
    int N, K; cin >> N >> K;
    vector<vector<int>> g(N);
    REP(i, N-1) {
        int u, v; cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    auto check = [&](int t) {
        // ans <= t ?
        int cnt = 0;
        vector<int> used;
        function<pair<int,int>(int,int)> dfs = [&](int u, int p) {
            int min_x = INF, max_y = -1;
            for (int v : g[u]) {
                if (v == p) continue;
                auto [x, y] = dfs(v, u);
                chmin(min_x, x);
                chmax(max_y, y);
            }
            if (min_x != INF and min_x + max_y + 2 <= t) {
                // already covered
                return make_pair(min_x + 1, -1);
            } else if (max_y + 1 == t) {
                // use
                ++cnt;
                used.push_back(u);
                return make_pair(0, -1);
            } else {
                // skip
                return make_pair(min_x == INF ? INF : min_x + 1, max_y + 1);
            }
        };
        auto [x, y] = dfs(0, -1);
        if (y != -1) ++cnt;
        return cnt <= K;
    };

    int ok = N-1, ng = 0;
    while (abs(ok - ng) > 1) {
        int m = (ok + ng) / 2;
        (check(m) ? ok : ng) = m;
    }
    cout << ok << endl;
}
