#include <bits/stdc++.h>
using namespace std;
int flag = 0;
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> adj[n + 1];
  vector<int> ord(n + 1, 0);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector<int> dist(n + 1, -1);
  queue<int> q;
  q.push(1);
  dist[1] = 0;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (auto i : adj[top]) {
      if (dist[i] == -1) {
        q.push(i);
        dist[i] = dist[top] + 1;
      }
    }
  }
  int index, ans = INT_MIN;
  for (int i = 1; i <= n; i++) {
    if (dist[i] > ans) {
      ans = dist[i];
      index = i;
    }
  }
  for (int i = 1; i <= n; i++) dist[i] = -1;
  q.push(index);
  dist[index] = 0;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (auto i : adj[top]) {
      if (dist[i] == -1) {
        q.push(i);
        dist[i] = dist[top] + 1;
      }
    }
  }
  int ans1 = INT_MIN;
  for (int i = 1; i <= n; i++) ans1 = max(ans1, dist[i]);
  cout << ans1;
  return 0;
}
