#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
vector<long long int> primeFactors(int n) {
  vector<long long int> result;
  while (n % 2 == 0) {
    result.push_back(2);
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      result.push_back(i);
      n = n / i;
    }
  }
  if (n > 2) result.push_back(n);
  return result;
}
vector<long long int> SieveOfEratosthenes(int n) {
  vector<long long int> result;
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) result.push_back(p);
  return result;
}
vector<long long int> BFS(long long int start,
                          vector<long long int> adj[100000], long long int n) {
  queue<long long int> Q;
  map<long long int, bool> visited;
  vector<long long int> level(n + 1);
  Q.push(start);
  visited[start] = true;
  level[start] = 0;
  while (!Q.empty()) {
    long long int cur = Q.front();
    Q.pop();
    for (long long int i = 0; i < adj[cur].size(); i++) {
      if (visited[adj[cur][i]] == false) {
        Q.push(adj[cur][i]);
        visited[adj[cur][i]] = true;
        level[adj[cur][i]] = level[cur] + 1;
      }
    }
  }
  return level;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long int i;
  vector<long long int> adj[n + 1];
  long long int u, v;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long int m1 = INT_MIN;
  long long int index = -1;
  vector<long long int> first = BFS(1, adj, n);
  for (i = 0; i < first.size(); i++) {
    if (m1 < first[i]) {
      m1 = first[i];
      index = i;
    }
  }
  vector<long long int> second = BFS(index, adj, n);
  cout << *max_element(second.begin(), second.end()) << endl;
  return 0;
}
