#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010];
int vis[100010], dis[100010];
queue<pair<int, int> > qu;
int main() {
  int n, m, x, y;
  scanf("%d %d ", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d ", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  qu.push(pair<int, int>(1, 0));
  int l = -1;
  while (!qu.empty()) {
    pair<int, int> u = qu.front();
    qu.pop();
    if (vis[u.first]) continue;
    vis[u.first] = 1;
    l = u.first;
    for (int i = 0; i < adj[u.first].size(); i++)
      qu.push(pair<int, int>(adj[u.first][i], 0));
  }
  fill(vis, vis + 100010, 0);
  qu.push(pair<int, int>(l, 0));
  while (!qu.empty()) {
    pair<int, int> u = qu.front();
    qu.pop();
    if (vis[u.first]) continue;
    vis[u.first] = 1;
    dis[u.first] = u.second;
    l = u.first;
    for (int i = 0; i < adj[u.first].size(); i++)
      qu.push(pair<int, int>(adj[u.first][i], u.second + 1));
  }
  printf("%d", dis[l]);
  return 0;
}
