#include <bits/stdc++.h>
using namespace std;
int cnt[200005];
int a[200005];
int main() {
  int n;
  cin >> n;
  int mx = 0, mx1 = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    mx1 = mx;
    mx = max(a[i], mx);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != mx)
      cout << mx << endl;
    else {
      if (cnt[mx] > 1)
        cout << mx << endl;
      else
        cout << mx1 << endl;
    }
  }
  return 0;
}
