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

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

pair <int, int> dfs(int u, int v) {
    pair <int, int> ans{0, v};
    
    for (int x : edges[v]) {
        if (x == u) continue;
        auto temp = dfs(v, x);

        ans = max(ans, {temp.first + 1, temp.second});
    }

    return ans;
}

int main() {

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

    int n, k;
    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 u = dfs(1, 1).second;

    cout << (dfs(u, u).first + 1) / 2 << '\n';
    return 0;

}