#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, i, j, k, a, b;
  cin >> n >> m;
  vector<vector<int>> adj(n + 1);
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vector<int> dist(n + 1, 10000000);
  queue<int> q;
  int maxx, maxid;
  dist[1] = 0;
  q.push(1);
  maxx = 0;
  maxid = 1;
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    for (auto p : adj[id]) {
      if (dist[p] == 10000000) {
        dist[p] = dist[id] + 1;
        q.push(p);
        if (dist[p] > maxx) {
          maxx = dist[p];
          maxid = p;
        }
      }
    }
  }
  dist.assign(n + 1, 10000000);
  dist[maxid] = 0;
  q.push(maxid);
  maxx = 0;
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    for (auto p : adj[id]) {
      if (dist[p] == 10000000) {
        dist[p] = dist[id] + 1;
        q.push(p);
        if (dist[p] > maxx) {
          maxx = dist[p];
          maxid = p;
        }
      }
    }
  }
  cout << maxx << "\n";
  return 0;
}
