#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[100005];
long long int vis[100005];
long long int dist = 0, node;
void dfs(long long int x, long long int level) {
  vis[x] = 1;
  if (level > dist) {
    dist = level;
    node = x;
  }
  for (auto it : adj[x]) {
    if (!vis[it]) {
      dfs(it, level + 1);
    }
  }
}
int main() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  dist = 0;
  memset(vis, 0, sizeof(vis));
  dfs(node, 0);
  cout << dist << endl;
}
