import Control.Monad
import Data.Array
import Data.List
main = do
  n <- read <$> getLine
  xs <- replicateM (n-1) $ read <$> getLine
  let a = accumArray (flip (:)) [] (1,10^5) $ zip xs [2..]
      f [] = 0
      f is = maximum $ zipWith (+) [1..] $ reverse $ sort $ map (f . (a!)) is
  print $ f $ a!1