#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  vector<bool> used(n);
  function<pair<int, int>(int, int)> dfs = [&](int u, int d) {
    used[u] = true;
    pair<int, int> best = {d, u};
    for (int v : g[u]) {
      if (used[v]) continue;
      best = max(best, dfs(v, d + 1));
    }
    return best;
  };
  auto r = dfs(0, 0);
  for (int i = 0; i < n; i++) used[i] = false;
  auto ans = dfs(r.second, 0);
  cout << ans.first << '\n';
}
