#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
vector<long long> adj[100005];
int res = 0;
int dfs(int node, int pnode) {
  int val1 = 0, val2 = 0;
  for (int i : adj[node]) {
    if (i != pnode) {
      int temp = dfs(i, node);
      if (temp >= val1) {
        val2 = val1;
        val1 = temp;
      } else if (temp > val2) {
        val2 = temp;
      }
    }
  }
  res = max(res, (val1 + val2 + 1));
  return (val1 + 1);
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  cout << res - 1 << endl;
  return (0);
}
