#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, f;
  cin >> n;
  vector<int> v(n);
  priority_queue<int> pq;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    pq.push(v[i]);
  }
  s = pq.top();
  pq.pop();
  f = pq.top();
  for (int i = 0; i < n; ++i) {
    if (v[i] == f)
      cout << s << endl;
    else
      cout << f << endl;
  }
  return 0;
}
