#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
void run() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e6 + 5;
int main() {
  run();
  int n;
  cin >> n;
  vector<int> v(n);
  int fr = 0, sec = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (v[fr] <= v[i]) {
      sec = fr;
      fr = i;
    } else if (v[sec] < v[i])
      sec = i;
  }
  for (int i = 0; i < n; i++) {
    if (fr == i)
      cout << v[sec] << "\n";
    else
      cout << v[fr] << "\n";
  }
}
