#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
const string debug_line = "yolo";
const long long linf = 1e15 + 5;
const int BLOCK = 330;
int dp[100010];
bool visited[100010];
int level[100010];
vector<int> Adj[100010];
void DFS(int u, int p) {
  visited[u] = true;
  level[u] = level[p] + 1;
  for (auto &(t1) : (Adj[u])) {
    if (!visited[t1] && t1 != p) {
      DFS(t1, u);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int(i) = (0); (i) < (m); ++(i)) {
    int a, b;
    scanf("%d%d", &a, &b);
    Adj[a].push_back(b);
    Adj[b].push_back(a);
  }
  DFS(1, 0);
  int pos = -1;
  int max1 = -1;
  for (int(i) = (1); (i) < (n + 1); ++(i)) {
    if (level[i] > max1) {
      max1 = level[i];
      pos = i;
    }
  }
  for (int(i) = (0); (i) < (n + 1); ++(i)) {
    visited[i] = false;
    level[i] = 0;
  }
  DFS(pos, 0);
  int answer1 = -1;
  for (int(i) = (1); (i) < (n + 1); ++(i)) {
    answer1 = max(answer1, level[i]);
  }
  printf("%d\n", answer1 - 1);
  return 0;
}
