#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> g;
vector<bool> v;
vector<long long> d, p;
void bfs(long long a) {
  queue<long long> q;
  p[a] = a;
  q.push(a);
  v[a] = 1;
  while (!q.empty()) {
    long long node = q.front();
    q.pop();
    for (auto x : g[node])
      if (!v[x]) {
        v[x] = 1;
        q.push(x);
        p[x] = node;
        d[x] = d[node] + 1;
      }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> a(n);
  vector<bool> b(n);
  vector<long long> c(n);
  g = a;
  d = c;
  v = b;
  p = c;
  for (long long x, y, i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  bfs(0);
  long long k = 0, l;
  for (auto x : d) k = max(k, x);
  for (long long i = 0; i < n; i++)
    if (d[i] == k) {
      l = i;
      break;
    }
  v.clear();
  p.clear();
  d.clear();
  d = c;
  v = b;
  p = c;
  bfs(l);
  k = 0;
  for (auto x : d) k = max(k, x);
  cout << k << endl;
  return 0;
}
