#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], first = 0, second = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] >= first) {
      second = first;
      first = a[i];
    } else if (a[i] >= second) {
      second = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == first)
      cout << second << endl;
    else
      cout << first << endl;
  }
  return 0;
}
