#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const float PI = 3.14;
typedef map<string, int> msi;
typedef vector<pair<int, int> > vii;
typedef priority_queue<pair<int, int>, vector<pair<int, int> >,
                       greater<pair<int, int> > >
    pq;
vector<pair<int, int> >::iterator iter;
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int tab[1000005];
  int maxi1 = 0;
  int maxi2 = 0;
  int id;
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
    if (tab[i] > maxi1) {
      maxi1 = tab[i];
      id = i;
    }
    if (tab[i] > maxi2 && tab[i] < maxi1) {
      maxi2 = tab[i];
    }
  }
  if (maxi2 == 0) maxi2 = maxi1;
  for (int i = 0; i < n; i++) {
    if (i != id) {
      cout << maxi1 << '\n';
    } else
      cout << maxi2 << '\n';
  }
  return 0;
}
