#include <bits/stdc++.h>
using namespace std;
const long long INF=1e19+7;
int main()
{
	long long b,c; cin>>b>>c;
	vector<pair<long long,long long> >a;
	a.push_back(make_pair(b-c/2,b));
	if(c>=1) a.push_back(make_pair(-b-(c-1)/2,-b)); 
	if(c>=1) a.push_back(make_pair(-b,-b+(c-1)/2));
	if(c>=2) a.push_back(make_pair(b,b+(c-2)/2));
	long long cnt=-INF,ans=0;
	sort(a.begin(),a.end());
	for(int i=0;i<a.size();i++){
		cnt=max(cnt,a[i].first);
		if(a[i].second>=cnt){
			ans+=a[i].second-cnt+1;
			cnt=a[i].second+1;
		}
	}
	cout<<ans<<endl;
    return 0;
}
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
vector<int> v[200001];
array<int, 200001> jr, dkt, tdk, at, uj;
int n, k, a, b, l, r, m, hit;
void jrk(int x) {
    for(int &i:v[x]) if(i != at[x]) {
        at[i] = x, jr[i] = jr[x]+1, jrk(i);
    }
}
bool cek(int &x) {
    // cerr << x;
    fill(dkt.begin(), dkt.end(), 0x3f3f3f3f);
    fill(tdk.begin(), tdk.end(), 0);
    hit = 0;
    f(i,1,n) {
        int &z = uj[i];
        // cerr << ' ' << z;
        if(dkt[z]+tdk[z] <= x) {
            tdk[z] = -1;
        } else if(tdk[z] == x || (z == 1 && tdk[z] >= 0)) {
            ++hit, tdk[z] = -1, dkt[z] = 0;
        }
        tdk[at[z]] = max(tdk[at[z]], tdk[z]+1);
        dkt[at[z]] = min(dkt[at[z]], dkt[z]+1);
    }
    // cerr << '\n';
    return hit <= k;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    f(i,2,n) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    jrk(1);
    f(i,1,n) uj[i] = i;
    sort(uj.begin()+1, uj.begin()+n+1, [](int &i, int &j){
        return jr[i] > jr[j];
    });
    l = 1, r = n-1;
    while(l <= r) {
        m = (l+r)>>1;
        cek(m) ? r = m-1 : l = m+1;
    }
    cout << l << '\n';
}