#include <bits/stdc++.h>
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
using namespace std;
template <typename T>
inline void dump(const T& x) {
  cout << "[" << x << "]" << endl;
}
template <typename T>
inline void dump(const vector<T>& x) {
  for (const auto v : x) {
    cout << v << " ";
  }
  cout << endl;
}
template <typename T>
inline void sort_asc(vector<T>& x) {
  std::sort(x.begin(), x.end());
}
template <typename T>
inline void sort_desc(vector<T>& x) {
  std::sort(x.begin(), x.end(), greater<T>());
}
template <typename T>
inline T max_value(vector<T>& x) {
  return *max_element(x.begin(), x.end());
}
template <typename T>
inline T min_value(vector<T>& x) {
  return *min_element(x.begin(), x.end());
}
template <typename T>
inline T sum_value(vector<T>& x) {
  return accumulate(x.begin(), x.end(), 0ULL);
}
int main() {
  ull n;
  cin >> n;
  vector<ull> a;
  for (auto i = 0; i < n; i++) {
    ull tmp;
    cin >> tmp;
    a.emplace_back(tmp);
  }
  ull mv = max_value(a);
  for (auto i = 0; i < n; i++) {
    const ull current = a[i];
    if (current == mv) {
      vector<ull> prev(a.begin(), a.begin() + i);
      vector<ull> after(a.begin() + i + 1, a.end());
      std::copy(after.begin(), after.end(), std::back_inserter(prev));
      cout << max_value(prev) << endl;
    } else {
      cout << mv << endl;
    }
  }
  return 0;
}
