#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
int ans = INT_MIN;
vector<int> adj[MAX];
int far_node = -1;
void dfs(int src, int par, int depth) {
  if (depth > ans) ans = depth, far_node = src;
  for (auto &child : adj[src]) {
    if (child != par) {
      dfs(child, src, depth + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, -1, 1);
  dfs(far_node, -1, 1);
  cout << ans - 1 << "\n";
  return 0;
}
