def is_loop? n_pos, pos ,tree
  tree[n_pos].include? pos
end

def find_and_remove_zero_indegree_vertexes tree
 keys = tree.keys
 vertexes = tree.values.flatten.uniq
 (keys - vertexes).each do |v|
   tree.delete v
 end
 tree
end

N=gets.chomp.to_i

ARY=[]
# 試合形式で配列に入れる。
N.times do |i|
  ARY << gets.chomp.split.map(&:to_i).zip([i+1]*(N-1))
end

all_games = (1..N).to_a.combination(2).to_a
indexed_games = all_games.each_with_object({}).with_index do |(game, hash),idx|
  hash[game] = idx
end
tree = (0..((N-1)*N/2 - 1)).each_with_object({}) do |i,hash|
  hash[i] = []
end


begin
  ARY.each do |attr|
    pos = indexed_games[attr.shift.sort]
    attr.each do |game|
        n_pos = indexed_games[game.sort]
        tree[pos] << n_pos
        pos = n_pos
        raise if is_loop? n_pos, pos, tree
    end
  end
  cnt = 0
  until tree.keys.empty? do
    find_and_remove_zero_indegree_vertexes tree
    cnt += 1
  end
  puts cnt
rescue
  puts -1
end
