#include <bits/stdc++.h>
using namespace std;
template <class U, class V>
ostream& operator<<(ostream& os, const pair<U, V>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {
  in >> p.first >> p.second;
  return in;
}
long long n;
vector<vector<long long> > al;
pair<long long, long long> bfs(long long s) {
  queue<long long> q;
  q.push(s);
  long long d[n];
  bool mark[n];
  memset(mark, 0, sizeof(mark));
  ;
  mark[s] = 1;
  memset(d, 0, sizeof(d));
  ;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long v : al[u]) {
      if (!mark[v]) {
        mark[v] = 1;
        q.push(v);
        d[v] = d[u] + 1;
      }
    }
  }
  long long p = max_element(d, d + n) - d;
  return make_pair(p, d[p]);
}
int main() {
  long long m;
  scanf("%lld %lld", &n, &m);
  ;
  al = vector<vector<long long> >(n);
  while (m--) {
    long long x, y;
    scanf("%lld %lld", &x, &y);
    ;
    al[x - 1].push_back(y - 1);
    al[y - 1].push_back(x - 1);
  }
  long long fir = bfs(0).first;
  printf("%lld", bfs(fir).second);
  ;
  return 0;
}
