#include <bits/stdc++.h>
using namespace std;
vector<int> DiameterPath(const vector<vector<int>> &g) {
  int n = g.size();
  if (n == 1) return vector<int>{0};
  auto farthest = [&](int start) {
    vector<int> depth(n);
    function<void(int, int, int)> get_depth = [&](int u, int prev, int d) {
      depth[u] = d;
      for (auto v : g[u])
        if (v != prev) {
          get_depth(v, u, d + 1);
        }
    };
    get_depth(start, -1, 0);
    int maxd = 0;
    int res = 0;
    for (int i = 0; i < n; i++) {
      if (depth[i] > maxd) {
        maxd = depth[i];
        res = i;
      }
    }
    return res;
  };
  int s = farthest(0);
  int t = farthest(s);
  vector<int> diameter_path;
  function<void(int, int, vector<int> &)> construct = [&](int u, int prev,
                                                          vector<int> &path) {
    if (u == t) {
      diameter_path = path;
      return;
    }
    for (auto v : g[u])
      if (v != prev) {
        path.push_back(v);
        construct(v, u, path);
        path.pop_back();
      }
  };
  vector<int> tmp;
  tmp.push_back(s);
  construct(s, -1, tmp);
  return diameter_path;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  assert(m == n - 1);
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  auto p = DiameterPath(g);
  printf("%d\n", (int)p.size() - 1);
  return 0;
}
