#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> v;
int n1, n2;
int ma = -1;
int dis(int node, int par, int len) {
  for (auto i : v[node]) {
    if (i != par) {
      int d = dis(i, node, len + 1);
      if (d > ma) {
        ma = d;
        n2 = i;
      }
    }
  }
  return len;
}
int func(int x, int y, int l, int par) {
  int mi = -1;
  for (auto i : v[x]) {
    if (i == y) return l + 1;
    if (i != par) {
      int a = func(i, y, l + 1, x);
      if ((mi == -1 || a < mi) && a != -1) mi = a;
    }
  }
  return mi;
}
int main() {
  cin >> n >> m;
  v = vector<vector<int>>(n + 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dis(1, -1, 0);
  n1 = n2;
  ma = -1;
  dis(n1, -1, 0);
  int dia = func(n1, n2, 0, -1);
  cout << dia;
  return 0;
}
