N = int(input()) P = list(map(int, input().split())) pre = [-1] * (N + 1) nex = [-1] * (N + 1) for i in range(1, N - 1): pre[P[i]] = P[i - 1] nex[P[i]] = P[i + 1] pre[P[-1]] = P[-2] nex[P[0]] = P[1] nil = 0 pre[P[0]] = nil nex[P[-1]] = nil res = [] for i in range(1, N + 1): if nex[i] == nil: continue res.extend([i, nex[i]]) nex[pre[i]] = nex[nex[i]] pre[nex[nex[i]]] = pre[i] # 存在確認用 nex[nex[i]] = nex[i] = nil print(' '.join(map(str, res)))