#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> e[101101];
bool v[101101];
int ans, ans_id;
void dfs(int cur, int dep) {
  v[cur] = true;
  if (dep > ans) {
    ans = dep;
    ans_id = cur;
  }
  for (int i = 0; i < (int)e[cur].size(); i++) {
    int nxt = e[cur][i];
    if (!v[nxt]) dfs(nxt, dep + 1);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  ans = -1;
  memset(v, false, sizeof v);
  dfs(1, 0);
  ans = -1;
  memset(v, false, sizeof v);
  dfs(ans_id, 0);
  printf("%d\n", ans);
  return 0;
}
