#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
long long int nC2(long long int num) {
  int num1 = num - 1;
  if (num % 2)
    num1 /= 2;
  else
    num /= 2;
  num *= num1;
  return num;
}
pair<int, int> BFS(int num, vector<vector<int>> adj_list, int n) {
  queue<pair<int, int>> Q;
  Q.push(make_pair(num, 0));
  int maxi = 0, maxi_at;
  vector<int> visited(n, 0);
  while (!Q.empty()) {
    auto p = Q.front();
    Q.pop();
    if (visited[p.first]) continue;
    visited[p.first] = 1;
    if (p.second >= maxi) {
      maxi = p.second;
      maxi_at = p.first;
    }
    for (int i = 0; i < adj_list[p.first].size(); i++) {
      if (visited[adj_list[p.first][i]]) continue;
      Q.push(make_pair(adj_list[p.first][i], p.second + 1));
    }
  }
  return make_pair(maxi, maxi_at);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj_list(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj_list[a].push_back(b);
    adj_list[b].push_back(a);
  }
  auto u = BFS(0, adj_list, n), v = BFS(u.second, adj_list, n);
  cout << v.first;
  return 0;
}
