#include <bits/stdc++.h>
using namespace std;
int dis[100009];
bool vis[100009];
int main() {
  int n, m, i, j, x, y, max = 0;
  cin >> n >> m;
  vector<int> u[n + 10];
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    u[x].push_back(y);
    u[y].push_back(x);
  }
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    x = q.front();
    q.pop();
    vis[x] = 1;
    for (auto k : u[x]) {
      if (!vis[k]) {
        dis[k] = dis[x] + 1;
        q.push(k);
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (dis[i] > max) {
      max = dis[i];
      j = i;
    }
  }
  dis[j] = 0;
  memset(vis, 0, n + 10);
  q.push(j);
  while (!q.empty()) {
    x = q.front();
    q.pop();
    vis[x] = 1;
    for (auto k : u[x]) {
      if (!vis[k]) {
        dis[k] = dis[x] + 1;
        q.push(k);
      }
    }
  }
  max = 0;
  for (i = 1; i <= n; i++) {
    if (dis[i] > max) max = dis[i];
  }
  cout << max;
  return 0;
}
