n = gets.chop.to_i
a = []
n.times do
  a[a.length] = gets.chop.split.map(&:to_i)
end

day = 0
done_match = []

while true do
  done_player = []
  day += 1
  player = 1
  while player <= n do
    for oppo in a[player-1] do
      next if done_match.include?([player, oppo].sort)
      break if done_player.include?(player) || done_player.include?(oppo)
      done_player << oppo
      done_player << player
      done_match << [player, oppo].sort
    end
    player += 1
  end
  next if done_player.any?
  day = day - 1
  break
end

p day
