#include <bits/stdc++.h>
using namespace std;
bool isvisited[100050];
vector<int> Edge[100050];
void bfs(int from, int &result, int &to) {
  for (int i = 0; i < 100050; i++) isvisited[i] = 0;
  list<int> worklist;
  list<int> worklist2;
  result = 0;
  worklist.push_back(from);
  while (!worklist.empty()) {
    to = worklist.front();
    while (!worklist.empty()) {
      int obj = worklist.front();
      isvisited[obj] = 1;
      for (vector<int>::iterator iter = Edge[obj].begin();
           iter != Edge[obj].end(); iter++) {
        if (isvisited[*iter] == 0) worklist2.push_back(*iter);
      }
      worklist.pop_front();
    }
    result++;
    worklist = worklist2;
    worklist2.clear();
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    Edge[a].push_back(b);
    Edge[b].push_back(a);
  }
  int to, result, to2;
  bfs(1, result, to);
  bfs(to, result, to2);
  printf("%d\n", result - 1);
  return 0;
}
