#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[100001];
bool seen[100001];
int dist[100001];
int u = -1, v = -1;
void bfs(int node) {
  fill_n(seen + 1, n, 0);
  fill_n(dist + 1, n, 0);
  queue<int> Q;
  Q.push(node);
  dist[node] = 0;
  seen[node] = 1;
  while (!Q.empty()) {
    int nn = Q.front();
    Q.pop();
    for (auto i : G[nn])
      if (!seen[i]) {
        seen[i] = 1;
        dist[i] = dist[nn] + 1;
        Q.push(i);
      }
  }
  u = 1;
  for (int i = 1; i <= n; i++)
    if (dist[u] < dist[i]) u = i;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  bfs(1);
  v = u;
  bfs(v);
  cout << dist[u];
}
