#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  int max;
  max = *max_element(a.begin(), a.end());
  b.erase(remove(b.begin(), b.end(), max), b.end());
  int second_max;
  second_max = *max_element(b.begin(), b.end());
  for (int i = 0; i < N; i++) {
    if (a[i] == max) {
      cout << second_max << endl;
    } else {
      cout << max << endl;
    }
  }
  return 0;
}
