#include <bits/stdc++.h>
using namespace std;
long long int vis[100005];
long long int lev[100005];
long long int bfs0(vector<long long int> v[], long long int pos,
                   long long int n) {
  memset(lev, 0, sizeof(lev));
  memset(vis, -1, sizeof(vis));
  queue<long long int> q;
  q.push(pos);
  vis[pos] = 1;
  lev[pos] = 0;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (long long int i = 0; i < v[x].size(); i += 1) {
      if (vis[v[x][i]] == -1) {
        vis[v[x][i]] = 1;
        lev[v[x][i]] = lev[x] + 1;
        q.push(v[x][i]);
      }
    }
  }
  long long int max = std::numeric_limits<long long int>::min();
  long long int p;
  for (long long int i = 1; i <= n; i += 1) {
    if (lev[i] > max) {
      max = lev[i];
      p = i;
    }
  }
  return p;
}
long long int bfs1(vector<long long int> v[], long long int pos,
                   long long int n) {
  memset(lev, 0, sizeof(lev));
  memset(vis, -1, sizeof(vis));
  queue<long long int> q;
  q.push(pos);
  lev[pos] = 0;
  vis[pos] = 1;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (long long int i = 0; i < v[x].size(); i += 1) {
      if (vis[v[x][i]] == -1) {
        vis[v[x][i]] = 1;
        lev[v[x][i]] = lev[x] + 1;
        q.push(v[x][i]);
      }
    }
  }
  long long int ans = std::numeric_limits<long long int>::min();
  for (long long int i = 1; i <= n; i += 1) ans = max(ans, lev[i]);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> v[n + 1];
  for (long long int i = 0; i < m; i += 1) {
    long long int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long int p = bfs0(v, 1, n);
  cout << bfs1(v, p, n);
  return 0;
}
