#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int mosttop = 0;
  long long int mostsec = 0;
  long long int n, m;
  bool ed = false;
  long long int a[n];
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> m;
    a[i] = m;
    ed = false;
    if (mosttop <= m) {
      mosttop = m;
      mostsec = n;
      ed = true;
    }
    if (mostsec < m && ed == false) {
      mostsec = m;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (a[i] == mosttop) {
      cout << mostsec << endl;
    } else {
      cout << mosttop << endl;
    }
  }
}
