#include <bits/stdc++.h>
using namespace std;
long long n, m;
struct qwq {
  long long num;
  long long down;
} a[200000];
long long b[200000];
long long cmp(qwq a, qwq b) { return a.num > b.num; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].num;
    b[i] = a[i].num;
    a[i].down = i;
  }
  sort(a + 1, a + n + 1, cmp);
  long long pos1 = a[1].num;
  long long pos2 = a[2].num;
  for (int i = 1; i <= n; i++) {
    if (pos1 != pos2) {
      if (b[i] == pos1) {
        cout << pos2 << endl;
      } else
        cout << pos1 << endl;
    } else
      cout << pos1 << endl;
  }
  return 0;
}
