#include <bits/stdc++.h>
using namespace std;
int visited[100005] = {0};
vector<int> graph[100005];
int distanc[100005] = {0};
void dfs(int node, int dis) {
  visited[node] = 1;
  distanc[node] = dis;
  for (int i : graph[node]) {
    if (!visited[i]) dfs(i, dis + 1);
  }
}
void diameter_of_tree(int n) {
  dfs(1, 0);
  int ma = 0, index;
  for (int i = 1; i <= n; i++) {
    if (distanc[i] > ma) {
      ma = distanc[i];
      index = i;
    }
  }
  memset(visited, 0, sizeof(visited));
  memset(distanc, 0, sizeof(distanc));
  dfs(index, 0);
  cout << *max_element(distanc, distanc + n + 2);
}
int main() {
  int n, m, a, b, i;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  diameter_of_tree(n);
  return 0;
}
