#include <bits/stdc++.h>
using namespace std;
map<long long int, vector<long long int>> graph;
bool isVisited[1000000] = {false};
pair<long long int, long long int> bfs(long long int start,
                                       long long int taille) {
  long long int dis[taille + 1];
  dis[0] = 0;
  memset(dis, 0, sizeof(dis));
  queue<long long int> q;
  isVisited[start] = true;
  q.push(start);
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (long long int i = 0; i < graph[s].size(); i++) {
      long long int v = graph[s][i];
      if (dis[v] == 0) {
        q.push(graph[s][i]);
        dis[v] = dis[s] + 1;
      }
    }
  }
  long long int maxDis = 0;
  long long int nodeMax = 0;
  for (long long int i = 1; i < taille + 1; i++) {
    if (dis[i] > maxDis) {
      maxDis = dis[i];
      nodeMax = i;
    }
  }
  return (make_pair(nodeMax, maxDis));
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int root;
  long long int h3;
  cin >> root >> h3;
  graph[root].push_back(h3);
  graph[h3].push_back(root);
  for (long long int i = 0; i < m - 1; i++) {
    long long int h1, h2;
    cin >> h1 >> h2;
    graph[h1].push_back(h2);
    graph[h2].push_back(h1);
  }
  if (m == 1) {
    cout << 1 << endl;
    return 0;
  }
  pair<long long int, long long int> t1, t2;
  t1 = bfs(root, graph.size());
  t2 = bfs(t1.first, graph.size());
  cout << t2.second << endl;
  return 0;
}
