#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e+9;
bool vis[100001];
long long int dist[100001];
void init() {
  for (long long int i = 0; i < 100001; i++) {
    vis[i] = false;
    dist[i] = 0;
  }
}
void bfs(long long int s, vector<long long int> adj[]) {
  dist[s] = 0;
  vis[s] = true;
  queue<long long int> q;
  q.push(s);
  while (!q.empty()) {
    long long int cur = q.front();
    q.pop();
    for (auto i : adj[cur]) {
      if (!vis[i]) {
        q.push(i);
        vis[i] = true;
        dist[i] = dist[cur] + 1;
      }
    }
  }
}
int32_t main() {
  init();
  long long int n, m;
  cin >> n >> m;
  vector<long long int> adj[n + 1];
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  bfs(1, adj);
  long long int d = 0, pos;
  for (long long int i = 1; i <= n; i++) {
    if (dist[i] > d) {
      pos = i;
      d = dist[i];
    }
  }
  init();
  bfs(pos, adj);
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) ans = max(ans, dist[i]);
  cout << ans;
  return 0;
}
