#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  priority_queue<int, vector<int>> pq;
  int MAX, second;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    pq.push(a.at(i));
  }
  MAX = pq.top();
  pq.pop();
  second = pq.top();
  for (int i = 0; i < N; i++) {
    if (a.at(i) == MAX)
      cout << MAX << endl;
    else
      cout << second << endl;
  }
}
