#define _GLIBCXX_FILESYSTEM
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;
vector <int> edges[MAXN];
int n, k;

int solve(int u, int v) {
    vector <int> vec;

    for (int x : edges[v]) {
        if (x == u) continue;
        vec.push_back(solve(v, x));
    }

    sort(vec.begin(), vec.end(), greater <int> ());

    int ans = 0;

    for (int i = 0; i < vec.size(); i++) {
        ans = max(ans, 1 + i / k + vec[i]);
    }

    return ans;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;

    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;

        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    int ans = INT_MAX;

    for (int u = 1; u <= n; u++) {
        ans = min(ans, solve(u, u));
    }

    cout << ans << '\n';
    return 0;

}