#include <bits/stdc++.h>
using namespace std;
template <class PerEdgeData, class PerVertexData>
class Graph {
 public:
  Graph(int nVertices, vector<PerVertexData> vertexData = {})
      : edges_(nVertices), vertexData_(move(vertexData)) {
    if (vertexData_.empty()) vertexData_.resize(nVertices);
  };
  void addEdge(size_t from, size_t to, PerEdgeData data = {}) {
    edges_[from].push_back({to, data});
    edges_[to].push_back({from, data});
  }
  void addUndirectedEdge(size_t from, size_t to, PerEdgeData data = {}) {
    edges_[from].push_back({to, data});
  }
  const vector<pair<size_t, PerEdgeData>>& vertexNeighbors(size_t vInd) const {
    return edges_[vInd];
  }
  const PerVertexData& getVertexData(int vInd) const {
    return vertexData_[vInd];
  }
  PerVertexData& getVertexData(int vInd) { return vertexData_[vInd]; }
  size_t vertexCount() const { return edges_.size(); }

 private:
  vector<vector<pair<size_t, PerEdgeData>>> edges_;
  vector<PerVertexData> vertexData_;
};
struct EmptyStruct {};
using SimpleGraph = Graph<EmptyStruct, EmptyStruct>;
template <typename T>
void relaxMax(T& relaxWhat, const T& relaxBy) {
  relaxWhat = std::max(relaxWhat, relaxBy);
}
template <typename T>
void relaxMin(T& relaxWhat, const T& relaxBy) {
  relaxWhat = std::min(relaxWhat, relaxBy);
}
class Solver622E {
 public:
  void run();
  vector<int> leavesDepths;
  unique_ptr<SimpleGraph> g;
  int depth = 1;
  void dfs(int v, int p) {
    bool isLeaf = true;
    for (auto pNei : g->vertexNeighbors(v)) {
      if (pNei.first == p) continue;
      isLeaf = false;
      ++depth;
      dfs(pNei.first, v);
      --depth;
    }
    if (isLeaf) leavesDepths.push_back(depth);
  }
};
void Solver622E::run() {
  int nVertices;
  cin >> nVertices;
  g.reset(new SimpleGraph(nVertices));
  for (int i = 0; i < nVertices - 1; ++i) {
    int a, b;
    cin >> a >> b;
    g->addEdge(a - 1, b - 1);
  }
  int ans = 0;
  for (auto pNei : g->vertexNeighbors(0)) {
    leavesDepths.clear();
    dfs(pNei.first, 0);
    sort(begin(leavesDepths), end(leavesDepths));
    int subAns = 0;
    for (auto d : leavesDepths) {
      ++subAns;
      relaxMax(subAns, d);
    }
    relaxMax(ans, subAns);
  }
  cout << ans;
}
using CurrentSolver = Solver622E;
int main() {
  ios::sync_with_stdio(false);
  CurrentSolver().run();
  return 0;
}
