#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[100001];
int dist[100001];
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  memset(dist, -1, sizeof(dist));
  dist[0] = 0;
  queue<int> que;
  que.push(0);
  while (que.size()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < G[v].size(); i++) {
      if (dist[G[v][i]] == -1) {
        dist[G[v][i]] = dist[v] + 1;
        que.push(G[v][i]);
      }
    }
  }
  int id = 0;
  for (int i = 0; i < n; i++) {
    if (dist[id] < dist[i]) {
      id = i;
    }
  }
  memset(dist, -1, sizeof(dist));
  dist[id] = 0;
  que.push(id);
  while (que.size()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < G[v].size(); i++) {
      if (dist[G[v][i]] == -1) {
        dist[G[v][i]] = dist[v] + 1;
        que.push(G[v][i]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    res = max(res, dist[i]);
  }
  printf("%d\n", res);
  return 0;
}
