#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> v[N];
bool visited[N];
void dfs(int node, int level, int distance[]) {
  visited[node] = true;
  distance[node] = level;
  for (int i = 0; i < v[node].size(); i++) {
    int child = v[node][i];
    if (!visited[child]) {
      dfs(child, level + 1, distance);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int distance[N];
  memset(distance, 0, sizeof(distance));
  dfs(1, 0, distance);
  int MAX = INT_MIN;
  int curr;
  for (int i = 1; i <= n; i++) {
    if (distance[i] > MAX) {
      MAX = distance[i];
      curr = i;
    }
  }
  memset(visited, false, sizeof(visited));
  memset(distance, 0, sizeof(distance));
  dfs(curr, 0, distance);
  MAX = INT_MIN;
  for (int i = 1; i <= n; i++) MAX = max(MAX, distance[i]);
  cout << MAX << endl;
  return 0;
}
