#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 5;
vector<int> sv[MAXN];
bool vis[MAXN];
pair<int, int> bfs(int now) {
  int i;
  pair<int, int> ret, t;
  ret.first = -1, ret.second = -1;
  memset(vis, false, sizeof(vis));
  queue<pair<int, int> > Q;
  Q.push(make_pair(now, 0));
  vis[now] = true;
  while (!Q.empty()) {
    t = Q.front();
    Q.pop();
    if (t.second > ret.second) {
      ret.first = t.first;
      ret.second = t.second;
    }
    for (i = 0; i < sv[t.first].size(); i++) {
      if (!vis[sv[t.first][i]]) {
        vis[sv[t.first][i]] = true;
        Q.push(make_pair(sv[t.first][i], t.second + 1));
      }
    }
  }
  return ret;
}
int main() {
  int n, i, a, b, m;
  pair<int, int> T;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    sv[a].push_back(b);
    sv[b].push_back(a);
  }
  T = bfs(1);
  T = bfs(T.first);
  printf("%d\n", T.second);
}
