#include <bits/stdc++.h>
int n, m;
std::vector<std::vector<int>> adjlist;
int farthestvertex;
int farthestdistance;
void dfs(int v, int distance, int parent) {
  if (distance > farthestdistance) {
    farthestvertex = v;
    farthestdistance = distance;
  }
  for (auto u : adjlist[v])
    if (u != parent) dfs(u, distance + 1, v);
}
struct vertexdistance {
  int vertex, distance;
};
vertexdistance farthestfrom(int v) {
  farthestvertex = v;
  farthestdistance = 0;
  dfs(v, 0, -1);
  return {farthestvertex, farthestdistance};
}
int main() {
  std::cin >> n >> m;
  adjlist.resize(n, {});
  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    a--, b--;
    adjlist[a].push_back(b);
    adjlist[b].push_back(a);
  }
  std::cout << farthestfrom(farthestfrom(0).vertex).distance << "\n";
  return 0;
}
