#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid (l+r>>1)
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define lowbit(x) (x&(-x))
#define inc(i, l, r) for(int i=l; i<=r; i++)
#define dec(i, r, l) for(int i=r; i>=l; i--)
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+10;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int mod = 1e9+7;
int readint()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll readll(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n, k;
struct Node{
int v, next, w;
}node[maxn<<1];
int tot, head[maxn];
void init(){
cls(head, -1);
tot = 0;
}
void add_edge(int u, int v, int w){
node[tot].v = v, node[tot].w = w, node[tot].next = head[u], head[u] = tot++;
node[tot].v=u, node[tot].w = w, node[tot].next = head[v], head[v] = tot++;
}
int dia;
int id1[maxn], id2[maxn];
int rt = -1;
int dfs(int u, int fa){
int mx1=0, mx2=0;
for(int i=head[u]; ~i; i=node[i].next){
int v=node[i].v;
if(v == fa) continue;
int len=node[i].w+dfs(v, u);
if(len>mx1) mx2=mx1, id2[u]=id1[u], mx1=len, id1[u]=i;
else if(len>mx2) mx2=len, id2[u]=i;
}
if(mx1+mx2>dia) dia = mx1+mx2, rt = u;
return mx1;
}
int main()
{
n=readint(), k=readint();
int u, v;
init();
inc(i, 1, n-1){
u=readint(), v=readint();
add_edge(u ,v, 1);
}
dia = 0;
int ans = 2*(n-1);
cls(id1, -1), cls(id2, -1);
dfs(1, 0);
ans -= (dia-1);
if(k == 2){
for(int i=id1[rt]; ~i; i=id1[node[i].v]) node[i].w = node[i^1].w = -1;
for(int i=id2[rt]; ~i; i=id1[node[i].v]) node[i].w = node[i^1].w = -1;
dia = -1;
dfs(1, 0);
ans -= (dia-1);
}
printf("%d\n", ans);
return 0;
}