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