#include <bits/stdc++.h>
using namespace std;
int cas = 1;
int dxx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dyy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
struct node {
  int x, y;
  bool operator<(const node& p) const { return x < p.x; }
};
vector<int> vc[100005];
int visit[100005], d[100005], mx, s;
void bfs(int u) {
  memset(visit, 0, sizeof(visit));
  visit[u] = 1;
  d[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < vc[u].size(); i++) {
      int v = vc[u][i];
      if (!visit[v]) {
        visit[v] = 1;
        d[v] = d[u] + 1;
        q.push(v);
        if (mx < d[v]) {
          mx = d[v];
          s = v;
        }
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    vc[x].push_back(y);
    vc[y].push_back(x);
  }
  mx = 0;
  s = 1;
  bfs(1);
  bfs(s);
  printf("%d\n", mx);
  return 0;
}
