#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0, p, q;
int ctr;
vector<vector<int> > gr;
bool mycomp(int a, int b) { return (a > b); }
int dfs(int now, int prev, int d) {
  vector<int> gg(gr[now].size() - 1);
  ans = max(ans, d);
  int ss = 0;
  for (int i = 0; i < gr[now].size(); i++) {
    if (gr[now][i] == prev) continue;
    gg[ss] = dfs(gr[now][i], now, d + 1);
    ss++;
  }
  if (gg.size() <= 1) {
    if (gg.size() == 0)
      return (d);
    else
      return (gg[0]);
  } else {
    sort(gg.begin(), gg.end(), mycomp);
    ans = max(ans, gg[0] + gg[1] - 2 * d);
    return (gg[0]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  gr.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d", &p, &q);
    p--;
    q--;
    gr[p].push_back(q);
    gr[q].push_back(p);
  }
  gr[0].push_back(-1);
  dfs(0, -1, 0);
  cout << ans;
}
