#include <bits/stdc++.h>
using namespace std;
vector<int> g[100020];
int level[100020];
int n, m;
void bfs(int src) {
  queue<int> Q;
  Q.push(src);
  bool visited[100020] = {false};
  memset(level, 0, sizeof(level));
  visited[src] = true;
  level[src] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (!visited[v]) {
        level[v] = level[u] + 1;
        visited[v] = true;
        Q.push(v);
      }
    }
    Q.pop();
  }
}
int main() {
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bfs(1);
  int node;
  int Max = -1;
  for (int i = 1; i <= n; i++) {
    if (level[i] > Max) {
      node = i;
      Max = level[i];
    }
  }
  bfs(node);
  Max = -1;
  for (int i = 1; i <= n; i++) {
    if (level[i] > Max) {
      Max = level[i];
    }
  }
  cout << Max << endl;
  return 0;
}
