#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
int mx, vis[100009], leaf[100009], l, d[100009], u, y;
void dfs(int x, int len, int r) {
  if (r)
    if (len > mx) {
      u = x;
      mx = len;
    } else if (r == 2) {
      if (len > mx) {
        y = x;
        mx = len;
      }
    }
  for (auto p : g[x]) {
    if (!vis[p]) {
      vis[p] = 1;
      dfs(p, len + 1, r);
    }
  }
}
int main() {
  int i, j;
  long long int n;
  cin >> (n);
  long long int m;
  cin >> (m);
  g.resize(n + 1);
  ;
  for (i = (1); i <= (m); i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vis[1] = 1;
  dfs(1, 0, 1);
  ;
  for (i = (1); i <= (n); i++) vis[i] = 0;
  vis[u] = 1;
  dfs(u, 0, 2);
  cout << mx;
  return 0;
}
