#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
vector<int> adj[100005];
int cnt, dist = 0, node = 1;
bool vis[100005];
void dfs(int u, int lvl, int par) {
  if (lvl > dist) {
    dist = lvl;
    node = u;
  }
  for (auto it : adj[u]) {
    if (it == par) continue;
    dfs(it, lvl + 1, u);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0, -1);
  dfs(node, 0, -1);
  cout << dist << endl;
}
