#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mo = 1e9 + 7;
vector<int> gra[maxn];
bool vis[maxn];
int n, m, cur = 1, ans;
int bfs(int x) {
  queue<int> q;
  int f = 0, pf = 0, ret = 0;
  q.push(x);
  q.push(-1);
  while (!q.empty()) {
    pf = f;
    f = q.front();
    q.pop();
    vis[f] = 1;
    if (f == -1 && !q.empty()) {
      ret++;
      q.push(-1);
      continue;
    }
    if (f != -1) {
      for (int i = 0; i < gra[f].size(); i++) {
        int to = gra[f][i];
        if (!vis[to]) {
          q.push(to);
        }
      }
    }
  }
  ans = ret;
  return pf;
}
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    gra[a].push_back(b);
    gra[b].push_back(a);
  }
  int a = bfs(1);
  for (int i = 0; i < maxn; i++) vis[i] = 0;
  int b = bfs(a);
  cout << ans << endl;
  return 0;
}
