#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> v[maxn];
int f[maxn];
int du[maxn];
int n;
struct node {
  int cnt, deep;
};
int pos;
void work() {
  queue<node> q;
  node c;
  c.cnt = 1;
  c.deep = 0;
  q.push(c);
  int ans = -1;
  pos = -1;
  while (!q.empty()) {
    node d = q.front();
    q.pop();
    f[d.cnt] = 1;
    if (ans < d.deep) {
      ans = d.deep;
      pos = d.cnt;
    }
    for (int i = 0; i < v[d.cnt].size(); i++) {
      if (f[v[d.cnt][i]]) continue;
      c.deep = d.deep + 1;
      c.cnt = v[d.cnt][i];
      q.push(c);
    }
  }
}
void bfs() {
  queue<node> q;
  node c;
  c.cnt = pos;
  c.deep = 0;
  q.push(c);
  int ans = -1;
  while (!q.empty()) {
    node d = q.front();
    q.pop();
    f[d.cnt] = 1;
    if (ans < d.deep) {
      ans = d.deep;
      pos = d.cnt;
    }
    for (int i = 0; i < v[d.cnt].size(); i++) {
      if (f[v[d.cnt][i]]) continue;
      c.deep = d.deep + 1;
      c.cnt = v[d.cnt][i];
      q.push(c);
    }
  }
  printf("%d\n", ans);
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
    du[b]++;
  }
  work();
  memset(f, 0, sizeof(f));
  bfs();
  return 0;
}
