#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(5e5) + 322;
const long long INF = (long long)(1e9);
const long long mod = (long long)(1e9) + 7;
const double eps = 1e-9;
int n, u[N], mx, val;
vector<int> v[N];
void dfs(int x, int h = 1) {
  u[x] = 1;
  if (h > mx) mx = h, val = x;
  for (auto &to : v[x])
    if (!u[to]) dfs(to, h + 1);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  int m;
  cin >> n >> m;
  for (long long i = 1; i <= n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long res = 0;
  dfs(1);
  memset(u, 0, sizeof u);
  dfs(val);
  cout << mx - 1 << "\n";
  return 0;
}
