#include <iostream>
#include <vector>
#include <algorithm>
std::vector<int> restoreSegmentTree(int n, std::vector<int>& values) {
   std::vector<int> originalArray(n, 0);
   std::vector<std::tuple<int, int, int>> stack; // (start, end, index in values)
   stack.push_back(std::make_tuple(0, n - 1, 1));
   int rootIndex = 0;
   while (!stack.empty()) {
       auto [start, end, index] = stack.back();
       stack.pop_back();
       if (start == end) {
           originalArray[start] = values[index - 1];
       } else {
           int leftChildIndex = 2 * index;
           int rightChildIndex = 2 * index + 1;
           int leftChildValue = values[leftChildIndex - 1];
           int rightChildValue = values[rightChildIndex - 1];
           int minValue = std::min(leftChildValue, rightChildValue);
           if (minValue == leftChildValue) {
               stack.push_back(std::make_tuple(start, (start + end) / 2, leftChildIndex));
               stack.push_back(std::make_tuple((start + end) / 2 + 1, end, rightChildIndex));
           } else {
               stack.push_back(std::make_tuple((start + end) / 2 + 1, end, rightChildIndex));
               stack.push_back(std::make_tuple(start, (start + end) / 2, leftChildIndex));
           }
           originalArray[(start + end) / 2] = minValue;
       }
   }
   for (int i = 1; i < n; ++i) {
       if (originalArray[i] <= originalArray[i - 1]) {
           return {-1}; // It's impossible to restore the original array
       }
   }
   return originalArray;
}
int main() {
   int n;
   std::cin >> n;
   std::vector<int> values(n);
   for (int i = 0; i < n; ++i) {
       std::cin >> values[i];
   }
   std::vector<int> originalArray = restoreSegmentTree(n, values);
   if (originalArray[0] == -1) {
       std::cout << -1 << std::endl;
   } else {
       for (int i = 0; i < n; ++i) {
           std::cout << originalArray[i] << " ";
       }
       std::cout << std::endl;
   }
   return 0;
}
