#include <bits/stdc++.h>
using namespace std;
long long max_ll(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
long long min_ll(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
long long dist[100005];
long long vis[100005];
void bfs(vector<vector<long long>> &v, long long node, long long n) {
  queue<long long> q;
  q.push(node);
  vis[node] = 1;
  dist[node] = 0;
  while (q.empty() == false) {
    long long x = q.front();
    q.pop();
    long long count = 0;
    for (long long i = 0; i < v[x].size(); i++) {
      if (vis[v[x][i]] == 0) {
        vis[v[x][i]] = 1;
        q.push(v[x][i]);
        dist[v[x][i]] = dist[x] + 1;
      }
    }
  }
}
void solve() {
  long long n, k, res = 0;
  cin >> n >> k;
  memset(dist, 0, sizeof(dist));
  memset(vis, 0, sizeof(vis));
  vector<vector<long long>> v(n + 1, vector<long long>());
  map<long long, long long> m;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (long long i = 1; i <= n; i++) {
    m[v[i].size()] = i;
  }
  long long node = m.begin()->second;
  bfs(v, node, n);
  pair<long long, long long> mm = {0, 0};
  for (long long i = 1; i <= n; i++) {
    if (dist[i] > mm.second) {
      mm = {i, dist[i]};
    }
  }
  memset(vis, 0, sizeof(vis));
  bfs(v, mm.first, n);
  for (long long i = 1; i <= n; i++) {
    res = max(res, dist[i]);
  }
  cout << res << '\n';
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
