#include <bits/stdc++.h>
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};
using namespace std;
const int mx = 100005;
int dis[mx];
vector<int> adj[mx];
int ans, hi;
void dfs(int u, int p, int le) {
  if (le > ans) {
    ans = le;
    hi = u;
  }
  for (int v : adj[u]) {
    if (v != p) dfs(v, u, le + 1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, -1, 0);
  dfs(hi, -1, 0);
  cout << ans << endl;
}
