#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 7;
const int M = 59;
const int mid = M / 2;
const int mod = 1e9 + 9;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const double ep = 1e-5;
const int maxn = 1e5 + 7;
const double PI = acos(-1);
int n, m;
vector<int> adj[N];
int d[N];
void DFS(int u, int r) {
  for (int j = (0); j < (adj[u].size()); j++) {
    int v = adj[u][j];
    if (v != r) {
      d[v] = d[u] + 1;
      DFS(v, u);
    }
  }
}
void solve() {
  cin >> n >> m;
  for (int t = (0); t < (m); t++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(1, -1);
  int mx = 1;
  for (int u = (1); u < (n + 1); u++)
    if (d[mx] < d[u]) mx = u;
  d[mx] = 0;
  DFS(mx, -1);
  for (int u = (1); u < (n + 1); u++)
    if (d[mx] < d[u]) mx = u;
  cout << d[mx];
}
int main() {
  int T = 1;
  for (int i = (1); i < (T + 1); i++) {
    solve();
  }
}
