#include <bits/stdc++.h>
using namespace std;
long long bin_exp(long long a, long long n, long long m) {
  long long res = 1;
  while (n) {
    if (n % 2 == 0) {
      a = ((a % m) * (a % m)) % m;
      n /= 2;
    } else {
      res = ((res % m) * (a % m)) % m;
      --n;
    }
  }
  return res % m;
}
const int val = 100005;
vector<int> gra[val];
int lvl1[val], lvl2[val];
bool visit[val];
int n, m;
void bfs(int root, int lvl[]) {
  visit[root] = true;
  queue<int> q1;
  q1.push(root);
  lvl[root] = 0;
  while (!q1.empty()) {
    int tar = q1.front();
    q1.pop();
    for (int i = 0; i < gra[tar].size(); ++i) {
      if (visit[gra[tar][i]] != true) {
        visit[gra[tar][i]] = true;
        q1.push(gra[tar][i]);
        lvl[gra[tar][i]] = lvl[tar] + 1;
      }
    }
  }
}
void work() {
  cin >> n >> m;
  int i, x, y;
  for (i = 1; i <= m; ++i) {
    cin >> x >> y;
    gra[x].push_back(y);
    gra[y].push_back(x);
  }
  bfs(1, lvl1);
  int maxi = -1, root;
  for (i = 1; i <= n; ++i) {
    if (lvl1[i] > maxi) {
      maxi = lvl1[i];
      root = i;
    }
  }
  for (i = 1; i <= n; ++i) visit[i] = false;
  bfs(root, lvl2);
  cout << *max_element(lvl2 + 1, lvl2 + n + 1);
}
int main() {
  int test = 1;
  work();
  return 0;
}
