#include <bits/stdc++.h>
using namespace std;
bool vis[100100];
int arr[100100];
vector<int> g[100100];
int m, n;
void dfs(int node, int length) {
  vis[node] = 1;
  arr[node] = length;
  for (int i = 0; i < g[node].size(); i++)
    if (!vis[g[node][i]]) dfs(g[node][i], length + 1);
}
int main() {
  cin >> n >> m;
  int tmpnode = 0, mx = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  tmpnode = max_element(arr, arr + n + 1) - arr;
  memset(vis, 0, sizeof(vis));
  memset(arr, 0, sizeof(arr));
  dfs(tmpnode, 0);
  tmpnode = max_element(arr, arr + n + 1) - arr;
  mx = arr[tmpnode];
  cout << mx << endl;
  return 0;
}
