#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> vis, d;
void dfs(int v, int c) {
  d[v] = c;
  vis[v] = true;
  for (int u : g[v]) {
    if (!vis[u]) dfs(u, c + 1);
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  g.resize(n + 1, vector<int>());
  vis.resize(n + 1, false);
  d.resize(n + 1, -1);
  while (m--) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  int u = max_element(d.begin(), d.end()) - d.begin();
  vis.clear();
  vis.resize(n + 1, false);
  dfs(u, 0);
  cout << (*max_element(d.begin(), d.end())) << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
