use std::cmp::{max, min};
use std::io::{self, BufRead};
const M: usize = 200010;
const MOD: i64 = 998244353;
static mut LEVEL: [i32; M] = [0; M];
static mut DP: [[i32; 2]; M] = [[0; 2]; M];
static mut LOW: [i32; M] = [0; M];
static mut UP: [i32; M] = [0; M];
static mut BONUS: [i32; M] = [0; M];
static mut MX: i32 = 0;
static mut N: usize = 0;
static mut K: i32 = 0;
static mut EDGE: Vec<Vec<usize>> = Vec::new();
unsafe fn dfs1(x: usize, p: usize) {
for &it in &EDGE[x] {
if it != p {
UP[it] = UP[x] + 1;
if x == 1 {
LOW[it] = DP[x][0];
if DP[x][0] == LEVEL[it] + 1 {
LOW[it] = DP[x][1];
}
LOW[it] -= 1;
LOW[it] = max(LOW[it], 0);
} else {
LOW[it] = LOW[x];
let mut cur = DP[x][0];
if DP[x][0] == LEVEL[it] + 1 {
cur = DP[x][1];
}
cur -= 1;
cur = max(0, cur);
BONUS[it] = BONUS[x];
BONUS[it] += cur;
MX = max(MX, UP[it] + min(LOW[x] + BONUS[it], K));
}
dfs1(it, x);
}
}
}
unsafe fn dfs(x: usize, p: usize) {
for &it in &EDGE[x] {
if it != p {
dfs(it, x);
}
}
LEVEL[p] = max(LEVEL[p], LEVEL[x] + 1);
if DP[p][0] < LEVEL[p] {
std::mem::swap(&mut DP[p][0], &mut DP[p][1]);
DP[p][0] = LEVEL[p];
} else if LEVEL[x] + 1 > DP[p][1] {
DP[p][1] = LEVEL[x] + 1;
}
}
fn main() {
let stdin = io::stdin();
let mut input = stdin.lock().lines();
let t = 1; // Single test case for now
for _ in 0..t {
// Read n and k
let line = input.next().unwrap().unwrap();
let mut split = line.split_whitespace();
unsafe {
N = split.next().unwrap().parse().unwrap();
K = split.next().unwrap().parse().unwrap();
// Initialize arrays and vector of edges
EDGE = vec![Vec::new(); N + 1];
for i in 1..=N {
LEVEL[i] = 1;
}
// Read edges
for _ in 1..N {
let line = input.next().unwrap().unwrap();
let mut split = line.split_whitespace();
let x: usize = split.next().unwrap().parse().unwrap();
let y: usize = split.next().unwrap().parse().unwrap();
EDGE[x].push(y);
EDGE[y].push(x);
}
DP[1][0] = 1;
dfs(1, 0);
MX = DP[1][0];
UP[1] = 1;
MX += min(max(0, DP[1][1] - 1), K);
dfs1(1, 0);
println!("{}", min(MX, N as i32));
}
}
}