#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[200001];
  for (int i = 0; i < N; i++) cin >> a[i];
  int maxv = 0;
  bool DuplicateFrag = 0;
  for (int i = 0; i < N; i++) {
    if (maxv == a[i]) DuplicateFrag = 1;
    if (maxv < a[i]) maxv = a[i];
  }
  for (int i = 0; i < N; i++) {
    if (DuplicateFrag) {
      cout << maxv << endl;
    } else if (maxv == a[i]) {
      unsigned int maxv2 = 0;
      for (int j = 0; j < N; j++) {
        if (j == i)
          ;
        else {
          if (maxv2 < a[j]) maxv2 = a[j];
        }
      }
      cout << maxv2 << endl;
    } else
      cout << maxv << endl;
  }
  return 0;
}
