#include <bits/stdc++.h>
using namespace std;
int arr[1000001];
int terbesar, terbesar2;
int main() {
  int a, c = 0;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> arr[i];
    if (c == 0) {
      terbesar = arr[i];
      c++;
    }
    if (c == 1) {
      terbesar2 = arr[i];
      c++;
    }
    if (arr[i] > terbesar || arr[i] > terbesar2) {
      terbesar2 = terbesar;
      terbesar = arr[i];
    }
  }
  int terA, terB;
  if (terbesar > terbesar2) {
    terA = terbesar;
    terB = terbesar2;
  } else {
    terA = terbesar2;
    terB = terbesar;
  }
  for (int i = 0; i < a; i++) {
    if (arr[i] != terA)
      cout << terA;
    else
      cout << terB;
    cout << endl;
  }
}
