#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAXN = 1e5 + 100;
vector<int> g[MAXN];
vector<int> used(MAXN);
int u = 0, mxdist = 0;
int v = 0;
void dfs(int v, int steps) {
  used[v] = 1;
  if (steps > mxdist) {
    mxdist = steps;
    u = v;
  }
  for (auto to : g[v]) {
    if (!used[to]) dfs(to, steps + 1);
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  int root = 1;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(root, 0);
  int f = u;
  mxdist = 0;
  for (int i = 1; i <= n; i++) {
    used[i] = 0;
  }
  dfs(f, 0);
  cout << mxdist << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
}
