#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main() {
  int n, s, f;
  cin >> n;
  vector<int> v(n);
  priority_queue<int> pq;
  rep(i, n){
    cin >> v[i];
    pq.push(v[i]);
  }
  s = pq.front();
  pq.pop();
  f = pq.front();
  rep(i, n){
    if(v[i] == f) cout << s << endl;
    else cout << f << endl;
  }
  return 0;
}