#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> tree(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  int answer = 0;
  int x = 0;
  function<void(int, int, int)> dfs = [&](int u, int p, int len) {
    if (answer < len) {
      answer = len;
      x = u;
    }
    for (auto v : tree[u]) {
      if (v != p) {
        dfs(v, u, len + 1);
      }
    }
  };
  dfs(1, 0, 0);
  answer = 0;
  dfs(x, x, 0);
  cout << answer << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
