#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<int> dist(N);
bool visited[N];
int DFS(vector<int> adj[], int vertex) {
  visited[vertex] = true;
  dist[vertex] = 0;
  stack<int> st;
  st.push(vertex);
  while (!st.empty()) {
    int v = st.top();
    st.pop();
    for (int itm : adj[v]) {
      if (visited[itm] == false) {
        visited[itm] = true;
        st.push(itm);
        dist[itm] = dist[v] + 1;
      }
    }
  }
  int max = dist[0];
  int pos;
  for (int i = 0; i < dist.size(); i++) {
    if (dist[i] > max) {
      pos = i;
      max = dist[i];
    }
  }
  return pos;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> adj[n + 1];
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int y = DFS(adj, 1);
  memset(visited, false, sizeof(visited));
  cout << dist[DFS(adj, y)] << endl;
  return 0;
}
