#include <bits/stdc++.h>
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;
int main() {
  int n;
  std::cin >> n;
  vt<int> a(n);
  int num = 0, fi = 0, se = 0;
  for (int i = 0; i < (int)n; i++) {
    std::cin >> a[i];
    if (fi < a[i]) {
      num = i;
      fi = a[i];
    } else if (fi > a[i] && a[i] > se)
      se = a[i];
  }
  for (int i = 0; i < (int)n; i++) {
    if (i == num)
      std::cout << se << '\n';
    else
      std::cout << fi << '\n';
  }
  return 0;
}
