#include <bits/stdc++.h>
using namespace std;
void c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<long long> adj[100001];
vector<long long> vis(100001, 0);
long long maxnode, maxdis;
void dfs(long long v, long long d) {
  vis[v] = 1;
  if (d >= maxdis) {
    maxnode = v;
    maxdis = d;
  }
  for (auto u : adj[v])
    if (!vis[u]) dfs(u, d + 1);
}
int32_t main() {
  c();
  long long n, m;
  cin >> n >> m;
  long long x, y;
  for (long long i = (0); i < (m); i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  maxnode = -1;
  maxdis = -1;
  dfs(1, 0);
  for (long long i = (0); i < (100001); i++) vis[i] = 0;
  dfs(maxnode, 0);
  cout << maxdis;
  return 0;
}
