#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; class BipartiteMatching { public: std::vector> G_; std::vector match_; std::vector visit_; BipartiteMatching(int V) { G_.resize(V); } void add(int u, int v) { G_[u].push_back(v); } bool dfs(int v) { visit_[v] = true; for (int i = 0; i < (int)G_[v].size(); ++i) { int u = G_[v][i]; int w = match_[u]; if (w < 0 || (!visit_[w] && dfs(w))) { match_[v] = u; match_[u] = v; return true; } } return false; } int match() { int res = 0; match_.resize(G_.size(),-1); visit_.resize(G_.size()); for (int v = 0; v < (int)G_.size(); ++v) { if ( match_[v] >= 0 ) continue; fill(visit_.begin(), visit_.end(), false); if ( dfs(v) ) res++; } return res; } }; class StudentNumber { public: void solve(void) { int N; cin>>N; vector A(N); REP(i,N) cin>>A[i]; BipartiteMatching bm(2*N); REP(i,N) REP(j,N) { if ( j == A[i] ) continue; bm.add(i,j+N); } if ( bm.match() < N ) { cout<<-1<solve(); delete obj; return 0; } #endif