#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool vis[N];
vector<int> v[N];
int l[N];
void bfs(int i) {
  vis[i] = true;
  queue<int> q;
  q.push(i);
  l[i] = 1;
  while (!q.empty()) {
    int papa = q.front();
    q.pop();
    for (int j = 0; j < v[papa].size(); ++j) {
      if (!vis[v[papa][j]]) {
        vis[v[papa][j]] = true;
        q.push(v[papa][j]);
        l[v[papa][j]] = l[papa] + 1;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  bfs(1);
  int id = -1;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    if (mx < l[i]) {
      mx = l[i];
      id = i;
    }
  }
  for (int i = 0; i < N; ++i) {
    l[i] = 0;
    vis[i] = false;
  }
  bfs(id);
  mx = 0;
  for (int i = 1; i <= n; ++i) {
    if (mx < l[i]) {
      mx = l[i];
      id = i;
    }
  }
  cout << mx - 1 << '\n';
}
