#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
vector<int> adj[MAX];
int d[MAX];
void dfs(int u, int p = -1) {
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    d[v] = d[u] + 1;
    dfs(v, 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);
  int x = max_element(d + 1, d + n + 1) - d;
  d[x] = 0;
  dfs(x);
  cout << *max_element(d + 1, d + n + 1);
  return 0;
}
