#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
const long long inf = 1e18;
const long long minf = -(1e18);
const long long mod = 1e9 + 7;
const long long med = 1e9 + 9;
inline long long add(long long x, long long y) {
  x %= mod;
  y %= mod;
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline long long sub(long long x, long long y) {
  x %= mod;
  y %= mod;
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline long long mul(long long x, long long y) {
  x %= mod;
  y %= mod;
  return (x * 1ll * y) % mod;
}
long long power(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long ans = power(x, y / 2) % mod;
  ans *= ans;
  ans %= mod;
  if (y % 2) ans *= x;
  return ans % mod;
}
long long inv(long long x, long long y) {
  x += mod;
  y += mod;
  x %= mod;
  y %= mod;
  long long ret = (power(y, mod - 2) % mod) * x;
  return (ret % mod);
}
vector<int> adj[500001];
int dist[500001];
bool visited[500001];
int bfs(int i) {
  queue<int> q;
  q.push(i);
  visited[i] = true;
  vector<pair<int, int>> time;
  while (!q.empty()) {
    int temp = q.front();
    q.pop();
    for (int j = 0; j < adj[temp].size(); j++) {
      if (!visited[adj[temp][j]]) {
        visited[adj[temp][j]] = true;
        q.push(adj[temp][j]);
        dist[adj[temp][j]] = dist[temp] + 1;
      }
    }
    if (adj[temp].size() == 1 && temp != 1) {
      time.push_back({dist[temp], temp});
    }
  }
  sort(time.begin(), time.end());
  int maxi = time[0].first;
  time[0].second = maxi;
  for (int i = 1; i < time.size(); i++) {
    time[i].second = ((dist[time[i].second] > time[i - 1].second + 1)
                          ? (dist[time[i].second])
                          : (time[i - 1].second + 1));
    maxi = ((maxi > time[i].second) ? (maxi) : (time[i].second));
  }
  return maxi;
}
int main(int argc, char const *argv[]) {
  int n;
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  int x, y;
  for (int i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  visited[1] = true;
  int maxi = 0;
  for (int i = 0; i < adj[1].size(); i++) {
    int temp = bfs(adj[1][i]);
    maxi = ((maxi > temp + 1) ? (maxi) : (temp + 1));
  }
  cout << maxi;
  return 0;
}
