#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
int main() {
  int n;
  cin >> n;
  int ma = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (ma < a[i]) ma = a[i];
  }
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp = 0;
    if (a[i] != ma)
      cout << ma << endl;
    else {
      for (int j = 0; j < i; j++) {
        if (tmp < a[j]) tmp = a[j];
      }
      for (int k = i + 1; k < n; k++) {
        if (tmp < a[k]) tmp = a[k];
      }
      cout << tmp << endl;
    }
  }
  return 0;
}
