#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
int n, m;
vector<int> A[MAXN];
int d[MAXN];
void dfs(int nod) {
  for (int i = 0; i < A[nod].size(); i++) {
    int v = A[nod][i];
    if (d[v] == 0) {
      d[v] = d[nod] + 1;
      dfs(v);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    A[a].push_back(b);
    A[b].push_back(a);
  }
  d[1] = 1;
  dfs(1);
  int u = max_element(d + 1, d + n + 1) - d;
  fill(d + 1, d + n + 1, 0);
  d[u] = 1;
  dfs(u);
  int sol = *max_element(d + 1, d + n + 1);
  sol--;
  cout << sol << "\n";
  return 0;
}
