#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, d[100005];
vector<int> edges[100005];
bool vis[100005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  int ans = 0, node;
  queue<int> q;
  vis[1] = true;
  q.push(1);
  while (!q.empty()) {
    int f = q.front();
    node = f;
    q.pop();
    for (int y : edges[f]) {
      if (!vis[y]) {
        vis[y] = true;
        d[y] = d[f] + 1;
        q.push(y);
      }
    }
  }
  q.push(node);
  memset(vis, 0, sizeof vis);
  memset(d, 0, sizeof d);
  vis[node] = true;
  while (!q.empty()) {
    int f = q.front();
    node = f;
    q.pop();
    for (int y : edges[f]) {
      if (!vis[y]) {
        vis[y] = true;
        d[y] = d[f] + 1;
        ans = max(ans, d[y]);
        q.push(y);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
