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