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

(n+1).times{|k|
  tmp = []
  cnt = 0
  n.times{|i|
    (i+1...n).each{|j|
      if x[i].size==0 || x[j].size==0
        cnt += 1
        break
      end
      
      if x[i][0]==j+1 && x[j][0]==i+1
        tmp<<i
        tmp<<j
      end
    }
  }
  if cnt!=0
    p k+1
    exit
  elsif tmp.size==0
    p -1
    exit
  end
  tmp.uniq.each{|w|
    x[w].shift
  }
}
