#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
const int maxv = 1e5 + 10;
const double eps = 1e-9;
vector<int> G[maxv];
int dis[maxv], id, maxdis;
void dfs(int u, int fa) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    dis[v] = dis[u] + 1;
    dfs(v, u);
  }
  if (dis[u] > maxdis) {
    maxdis = dis[u];
    id = u;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  maxdis = 0;
  dfs(1, 1);
  maxdis = 0;
  memset(dis, 0, sizeof dis);
  dfs(id, id);
  printf("%d\n", maxdis);
  return 0;
}
