#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int v[n];
  int l1 = 0;
  int l2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i] > l1) {
      l2 = l1;
      l1 = v[i];
    } else {
      if (v[i] > l2 && v[i] != l1) {
        l2 = v[i];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (v[i] != l1)
      cout << l1 << endl;
    else
      cout << l2 << endl;
  }
}
