#include <bits/stdc++.h>
using namespace std;
int n, m, g;
vector<vector<int> > graph(100000);
int visited[100000];
struct node {
  int len;
  int index;
};
int dfs(int start) {
  memset(visited, 0, 4 * n);
  stack<node> stek;
  node temp, top;
  temp.len = 0;
  temp.index = start;
  visited[start] = 1;
  int r = 0, m = 0;
  stek.push(temp);
  while (!stek.empty()) {
    top = stek.top();
    stek.pop();
    if (top.len > m) {
      m = top.len;
      r = top.index;
    }
    temp.len = top.len + 1;
    for (int i = 0; i < graph[top.index].size(); i++) {
      int index = graph[top.index][i];
      if (!visited[index]) {
        visited[index] = 1;
        temp.index = index;
        stek.push(temp);
      }
    }
  }
  g = m;
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  int u, v;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    graph[u - 1].push_back(v - 1);
    graph[v - 1].push_back(u - 1);
  }
  dfs(dfs(u - 1));
  cout << g;
  return 0;
}
