#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int level[100005];
bool vis[100005];
int bfs_node(int source) {
  memset(vis, 0, sizeof(vis));
  ;
  queue<int> vc;
  int a, b, mx = 0, id = 0;
  level[source] = 0;
  vis[source] = 1;
  vc.push(source);
  while (!vc.empty()) {
    a = vc.front();
    vc.pop();
    for (int i = 0; i < adj[a].size(); i++) {
      b = adj[a][i];
      if (vis[b] == 0) {
        level[b] = level[a] + 1;
        vis[b] = 1;
        vc.push(b);
        if (mx <= level[b]) {
          mx = level[b];
          id = b;
        }
      }
    }
  }
  return id;
}
int bfs(int source) {
  memset(vis, 0, sizeof(vis));
  ;
  queue<int> vc;
  int a, b, mx = 0;
  level[source] = 0;
  vis[source] = 1;
  vc.push(source);
  while (!vc.empty()) {
    a = vc.front();
    vc.pop();
    for (int i = 0; i < adj[a].size(); i++) {
      b = adj[a][i];
      if (vis[b] == 0) {
        level[b] = level[a] + 1;
        mx = max(level[b], mx);
        vis[b] = 1;
        vc.push(b);
      }
    }
  }
  return mx;
}
int main() {
  int n, m, s;
  cin >> n >> m;
  for (int i = 0; i < 100005; i++) adj[i].clear();
  ;
  memset(level, 0, sizeof(level));
  ;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ans = 0;
  ans = bfs(bfs_node(1));
  cout << ans << endl;
  return 0;
}
