#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> v;
long long int cnt, ans, idx, ans1;
long long int cnt1;
long long int vis[1000000];
long long int vis1[1000000];
long long int freq[1000000];
long long int freq1[1000000];
queue<pair<long long int, long long int>> q;
queue<pair<long long int, long long int>> q1;
void BFS1(long long int a) {
  q1.push({a, 0});
  while (!q1.empty()) {
    pair<long long int, long long int> h = q1.front();
    long long int f = h.first;
    long long int g = h.second;
    q1.pop();
    for (unsigned long long int j = 0; j < v[f].size(); j++) {
      if (!vis1[v[f][j]]) {
        q1.push({v[f][j], g + 1});
        vis1[v[f][j]] = 1;
        freq1[v[f][j]] = g + 1;
      }
    }
    cnt1++;
  }
}
void BFS(long long int a) {
  q.push({a, 0});
  while (!q.empty()) {
    pair<long long int, long long int> h = q.front();
    long long int f = h.first;
    long long int g = h.second;
    q.pop();
    for (unsigned long long int j = 0; j < v[f].size(); j++) {
      if (!vis[v[f][j]]) {
        q.push({v[f][j], g + 1});
        vis[v[f][j]] = 1;
        freq[v[f][j]] = g + 1;
      }
    }
    cnt++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, a, b, m;
  cin >> n >> m;
  v.resize(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  cnt++;
  vis[1] = 1;
  freq[1] = 0;
  BFS(1);
  for (int i = 1; i <= n; i++) ans = max(ans, freq[i]);
  for (int i = 1; i <= n; i++) {
    if (freq[i] == ans) idx = i;
  }
  cnt1++;
  vis1[idx] = 1;
  freq1[idx] = 0;
  BFS1(idx);
  for (int i = 1; i <= n; i++) ans1 = max(ans1, freq1[i]);
  cout << ans1;
  return 0;
}
