#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int used[100005], d[100005];
vector<int> g[100005];
void bfs(int node) {
  memset(used, 0, sizeof(used));
  memset(d, 0, sizeof(d));
  queue<int> q;
  q.push(node);
  used[node] = 1;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < g[cur].size(); i++) {
      int to = g[cur][i];
      if (!used[to]) {
        q.push(to);
        d[to] = d[cur] + 1;
        used[to] = 1;
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &a);
    scanf("%d", &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bfs(1);
  int start = 1, dis = 0;
  for (int i = 2; i <= n; i++) {
    if (dis < d[i]) {
      dis = d[i];
      start = i;
    }
  }
  bfs(start);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, d[i]);
  }
  cout << ans << endl;
  return 0;
}
