#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n;
int a[200005];
int nax1 = -1, nax2 = -2;

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  
  for(int i = 1; i <= n; i++) {
    if(nax1 < a[i]) {
      nax2 = nax1;
      nax1 = a[i];
    } else if(nax2 < a[i]) {
      nax2 = a[i];
    }
    for(int i = 1; i <= n; i++) {
      if(a[i] == nax1) cout << nax2 << endl;
      else cout << nax1 << endl;
    }
  }
}
