#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1 << 20;
int n, m;
vector<int> nbr[SIZE];
bool used[SIZE];
int dist[SIZE];
void DFS(int u, int d) {
  used[u] = true;
  dist[u] = d;
  for (int i = 0; i < nbr[u].size(); i++) {
    int v = nbr[u][i];
    if (!used[v]) DFS(v, d + 1);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    nbr[a].push_back(b);
    nbr[b].push_back(a);
  }
  DFS(0, 0);
  int best = 0;
  for (int i = 0; i < n; i++)
    if (dist[i] > dist[best]) best = i;
  memset(used, 0, sizeof(used));
  DFS(best, 0);
  int best2 = 0;
  for (int i = 0; i < n; i++)
    if (dist[i] > dist[best2]) best2 = i;
  printf("%d\n", dist[best2]);
  return 0;
}
