#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100002];
int res = 0;
int far2 = 1;
int n, m;
void bfs2(int s) {
  queue<int> q;
  q.push(s);
  vector<bool> used(100010, false);
  vector<int> d(100010, 0);
  used[s] = true;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < graph[v].size(); ++i) {
      int to = graph[v][i];
      if (!used[to]) {
        used[to] = true;
        q.push(to);
        d[to] = d[v] + 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    res = max(res, d[i]);
    if (res == d[i]) far2 = i;
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  int a, b;
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &a);
    scanf("%d", &b);
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  bfs2(a);
  bfs2(far2);
  cout << res << endl;
  return 0;
}
