from collections import defaultdict n = int(input()) P = list(map(int, input().split())) G = defaultdict(int) RG = defaultdict(int) for i in range(n - 1): G[P[i]] = P[i + 1] G[P[n - 1]] = None for i in range(n - 1, 0, -1): RG[P[i]] = P[i - 1] RG[P[0]] = None ANS = [] for i in range(1, n + 1): nex = G[i] if nex is None: continue ANS.append(i) ANS.append(nex) new_nex = G[nex] G[i] = None G[nex] = None pre = RG[i] if pre is not None: G[pre] = new_nex if new_nex is not None: RG[new_nex] = pre print(*ANS)