#include <bits/stdc++.h>
using namespace std;
vector<bool> mark;
vector<vector<int> > orig, graph;
int n, m;
void DFS(int vertex) {
  mark[vertex] = 1;
  for (int i : orig[vertex]) {
    if (!mark[i]) {
      graph[vertex].push_back(i);
      graph[i].push_back(vertex);
      DFS(i);
    }
  }
}
pair<int, int> BFS(int vertex = 0) {
  int max_dist = 0, farthest_node = 0;
  const int INF = 1e9;
  vector<int> dist(n, INF);
  dist[vertex] = 0;
  queue<int> q;
  q.push(vertex);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i : graph[v]) {
      if (dist[i] > dist[v] + 1) {
        dist[i] = dist[v] + 1;
        q.push(i);
        if (max_dist < dist[i]) {
          max_dist = dist[i];
          farthest_node = i;
        }
      }
    }
  }
  return {max_dist, farthest_node};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  mark.resize(n);
  orig.resize(n);
  graph.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    orig[a].push_back(b);
    orig[b].push_back(a);
  }
  DFS(0);
  int a = BFS().second;
  int diameter = BFS(a).first;
  cout << diameter << endl;
  return 0;
}
