N,*A=$<.map &:to_i p *(0..999).map{[*0...N].shuffle}.find{|b|i=-1;b.all?{|b|b!=A[i+=1]}}||-1