#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 55;
int crr, longest, visID, n, m, u, v;
int vis[N];
vector<int> adj[N];
void dfs(int v, int lvl = 0) {
  vis[v] = visID;
  if (lvl > crr) {
    crr = lvl;
    longest = v;
  }
  for (int a : adj[v]) {
    if (vis[a] == visID) continue;
    dfs(a, lvl + 1);
  }
}
int find_diameter() {
  visID = 1;
  dfs(1);
  visID = 2;
  crr = 0;
  dfs(longest);
  return crr;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cout << find_diameter() << '\n';
  return 0;
}
