#include <bits/stdc++.h>
using namespace std;
int maxDis = 0, maxDisVer = 0;
void dfs(int v, vector<int> *adj, bool *mark, int *dis) {
  mark[v] = true;
  for (int i = 0; i < adj[v].size(); i++) {
    int nbr = adj[v][i];
    dis[nbr] = min(dis[v] + 1, dis[nbr]);
    if (dis[nbr] > maxDis) maxDis = dis[nbr], maxDisVer = nbr;
    if (!mark[nbr]) dfs(nbr, adj, mark, dis);
  }
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  vector<int> adj[n + 1];
  int dis[n + 1];
  bool mark[n + 1];
  for (int i = 0; i <= n; i++) mark[i] = 0, dis[i] = 100001;
  dis[1] = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, adj, mark, dis);
  for (int i = 0; i <= n; i++) mark[i] = 0, dis[i] = 100001;
  dis[maxDisVer] = 0;
  dfs(maxDisVer, adj, mark, dis);
  cout << maxDis;
}
