#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n;
int A[MAXN];
int freq[MAXN];
int main() {
  cin >> n;
  int mx = 0, mmx = 0;
  for (int i = (0); i < (n); i++) {
    cin >> A[i];
    freq[A[i]]++;
    if (A[i] > mx) {
      mmx = mx;
      mx = A[i];
    } else if (A[i] > mmx) {
      mmx = A[i];
    }
  }
  for (int i = (0); i < (n); i++) {
    if (A[i] < mx)
      cout << mx << "\n";
    else if (A[i] == mx) {
      freq[mx]--;
      if (freq[mx] == 0)
        cout << mmx << "\n";
      else
        cout << mx << "\n";
    }
    freq[mx]++;
  }
  return 0;
}
