#include <bits/stdc++.h>
using namespace std;
bool vis[200005];
vector<int> graph[200005], dis(200005);
long long int n, m;
void dfs(int p, int d) {
  dis[p] = d;
  vis[p] = true;
  for (auto c : graph[p]) {
    if (!vis[c]) {
      dfs(c, d + 1);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    long long int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(1, 0);
  int root = 1, cd = 0;
  for (int i = 0; i < (n); i++) {
    if (dis[i + 1] >= cd) {
      root = i + 1;
      cd = dis[i + 1];
    }
  }
  memset(vis, 0, sizeof(vis));
  dfs(root, 0);
  for (int i = 0; i < (n); i++) {
    cd = max(cd, dis[i + 1]);
  }
  cout << cd;
  return 0;
}
