#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200005];
vector<long long> vis(200005);
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k = 0, n, t = 1, l = 0;
  for (i = 0; i < 200005; i++) vis[i] = 0;
  while (t--) {
    long long m;
    cin >> n >> m;
    for (i = 0; i < m; i++) {
      cin >> k >> l;
      adj[k].push_back(l);
      adj[l].push_back(k);
    }
    long long leaf = 0, leaf1 = 0;
    long long d[n + 1];
    for (i = 0; i <= n; i++) d[i] = 100000000000;
    queue<long long> q;
    d[1] = 0;
    q.push(1);
    vis[1] = 1;
    while (!q.empty()) {
      long long s = q.front();
      q.pop();
      for (auto u : adj[s]) {
        if (vis[u]) continue;
        vis[u] = 1;
        d[u] = d[s] + 1;
        leaf = u;
        q.push(u);
      }
    }
    for (i = 0; i < 200005; i++) vis[i] = 0;
    for (i = 0; i <= n; i++) d[i] = 100000000000;
    d[leaf] = 0;
    q.push(leaf);
    vis[leaf] = 1;
    while (!q.empty()) {
      long long s = q.front();
      q.pop();
      for (auto u : adj[s]) {
        if (vis[u]) continue;
        vis[u] = 1;
        d[u] = d[s] + 1;
        leaf1 = u;
        q.push(u);
      }
    }
    cout << d[leaf1] << "\n";
  }
  return 0;
}
