#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];
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
  }
  int id;
  int maxi;
  int maxi2;
  if (tab[0] < tab[1]) {
    maxi = tab[1];
    id = 1;
    maxi2 = tab[0];
  } else {
    maxi = tab[0];
    id = 0;
    maxi2 = tab[1];
  }
  for (int i = 2; i < n; i++) {
    if (tab[i] > maxi) {
      maxi2 = maxi;
      maxi = tab[i];
      id = i;
    } else if (tab[i] > maxi2 && tab[i] != maxi) {
      maxi2 = tab[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != id) {
      cout << maxi << "\n";
    } else
      cout << maxi2 << "\n";
  }
  return 0;
}
