#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool vis[100001];
vector<int> arr[100001];
int dis[100001];
bool ch = false;
void dfs(int x, int d) {
  vis[x] = true;
  dis[x] = d;
  for (unsigned int i = 0; i < arr[x].size(); i++) {
    if (!vis[arr[x][i]]) dfs(arr[x][i], dis[x] + 1);
  }
}
int main() {
  for (int i = 0; i < 100001; i++) dis[i] = 0;
  int a = 0, b = 0;
  cin >> n >> m;
  for (int i = 0; i < 100001; i++) vis[i] = false;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  dfs(1, 0);
  int max = 0, ind;
  for (int i = 0; i < 100001; i++)
    if (dis[i] > max) {
      max = dis[i];
      ind = i;
    }
  for (int i = 0; i < 100001; i++) dis[i] = 0;
  for (int i = 0; i < 100001; i++) vis[i] = false;
  dfs(ind, 0);
  max = 0;
  for (int i = 0; i < 100001; i++)
    if (dis[i] > max) {
      max = dis[i];
      ind = i;
    }
  cout << max << endl;
  return 0;
}
