#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N, A[50]; bool used[50], eUsed[50][50], reUsed[50][50]; struct E{ int to, cap, rev; }; vector G[50]; void add(int from, int to){ G[from].push_back(E{to,1,(int)G[to].size()}); G[to].push_back(E{from,0,(int)G[from].size() - 1}); } int dfs(int v, int f){ if(v == 2*N+1) return f; used[v] = 1; for(auto &e : G[v]){ if(!used[e.to] && e.cap > 0){ int d = dfs(e.to, min(e.cap, f)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } int get(){ int f = 1, res = 0; while(f){ MEM(used, 0); f = dfs(2 * N, INT_MAX); res += f; } return res; } int main(){ cin >> N; rep(i, N){ cin >> A[i]; rep(j, N)if(j != A[i]) add(i, N+j); add(2 * N, i); add(N + i, 2 * N + 1); } int cnt = get(); if(cnt == N){ rep(i, N){ each(e, G[i]){ int j = e.to - N; if(0 <= j && j < N && !e.cap){ eUsed[i][j] = 1; } } each(e, G[N+i]){ int j = e.to; if(0 <= j && j < N && !e.cap) reUsed[j][i] = 1; } } rep(i, N)rep(j, N){ if(!reUsed[i][j] && eUsed[i][j]){ cout << j << endl; } } } else{ puts("-1"); } }