#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
vector<int> veci[MAXN];
queue<int> q;
int solve[MAXN];
bool G[MAXN];
int mx, ans;
int n, m;
void bfs(int n) {
  while (q.size() > 0) {
    int v = q.front(), len = veci[v].size();
    for (int i = 0; i < len; i++) {
      if (G[veci[v][i]] == 0) {
        q.push(veci[v][i]);
        G[veci[v][i]] = 1;
      }
    }
    ans = v;
    q.pop();
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    veci[a].push_back(b), veci[b].push_back(a);
  }
  q.push(1);
  G[1] = 1;
  bfs(n);
  q.push(ans);
  fill(G, G + n, 0);
  G[ans] = 1;
  while (q.size() > 0) {
    int v = q.front();
    for (int i = 0; i < veci[v].size(); i++) {
      if (G[veci[v][i]] == 0) {
        q.push(veci[v][i]);
        solve[veci[v][i]] = solve[v] + 1;
        G[veci[v][i]] = 1;
      }
    }
    q.pop();
    mx = solve[v];
  }
  cout << mx;
}
