#include <bits/stdc++.h>
using namespace std;
vector<int> e[111111];
int n, m, anx, any;
int use[111111];
queue<int> que;
void bfs(int x) {
  memset(use, -1, sizeof(use));
  que.push(x);
  use[x] = 0;
  any = -1;
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int i = 0; i < e[now].size(); i++) {
      int nex = e[now][i];
      if (use[nex] == -1) {
        use[nex] = use[now] + 1;
        if (use[nex] > any) any = use[nex], anx = nex;
        que.push(nex);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--, y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  bfs(0);
  bfs(anx);
  printf("%d\n", any);
  return 0;
}
