#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> inS(n + 1, 0);
  vector<vector<int> > edge(n + 1, vector<int>());
  while (m--) {
    int a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  queue<int> q;
  inS[1] = 1;
  q.push(1);
  int last;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    last = u;
    for (int i = 0; i < edge[u].size(); ++i) {
      if (!inS[edge[u][i]]) {
        inS[edge[u][i]] = 1;
        q.push(edge[u][i]);
      }
    }
  }
  queue<pair<int, int> > qq;
  inS.clear();
  inS.resize(n + 1, 0);
  inS[last] = 1;
  qq.push({last, 0});
  while (!qq.empty()) {
    auto uu = qq.front();
    int u = uu.first;
    qq.pop();
    last = uu.second;
    for (int i = 0; i < edge[u].size(); ++i) {
      if (!inS[edge[u][i]]) {
        inS[edge[u][i]] = 1;
        qq.push({edge[u][i], uu.second + 1});
      }
    }
  }
  cout << last << endl;
  return 0;
}
