#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj(n + 1, vector<int>());
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<bool> vis1(n + 1, false);
  vector<bool> vis2(n + 1, false);
  vector<int> level1(n + 1, 0), level2(n + 1, false);
  int d = 0;
  queue<int> q;
  q.push(1);
  level1[1] = 0;
  vis1[1] = true;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (auto child : adj[node]) {
      if (!vis1[child]) {
        vis1[child] = true;
        level1[child] = 1 + level1[node];
        q.push(child);
      }
    }
  }
  int nod1 = 1, level = 0;
  for (int i = 1; i <= n; i++) {
    if (level1[i] > level) {
      level = level1[i];
      nod1 = i;
    }
  }
  queue<int> q1;
  q1.push(nod1);
  level2[nod1] = 0;
  vis2[nod1] = true;
  while (!q1.empty()) {
    int node = q1.front();
    q1.pop();
    for (auto child : adj[node]) {
      if (!vis2[child]) {
        vis2[child] = true;
        level2[child] = 1 + level2[node];
        q1.push(child);
      }
    }
  }
  int dia = 0;
  for (int i = 1; i <= n; i++) dia = max(dia, level2[i]);
  cout << dia << " ";
  cout << endl;
  return 0;
}
