n = gets.to_i
a = n.times.map{gets.split.map(&:to_i)}

total_games = n * (n - 1) / 2
games = 0
day = 1
last_day = Array.new(n, 0)
played_count = Array.new(n, 0)

while games < total_games do
  todays_games = 0
  for i in 0...n do
    if last_day[i] < day && played_count[i] < n - 1
      j = a[i][played_count[i]] - 1
      if last_day[j] < day && a[j][played_count[j]] - 1 == i
        last_day[i] = day
        last_day[j] = day
        played_count[i] += 1
        played_count[j] += 1
        todays_games += 1
      end
    end
  end
  if todays_games == 0
    day = 0
    break
  else
    games += todays_games
  end
  day += 1
end
puts day - 1
