#include <bits/stdc++.h>
using namespace std;
const long long e5 = 1 << 20;
const long long mod = 998244353;
const long long e3 = 1 << 13;
const long long INF = 1ll << 60;
int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  vector<int> a_num(n, 0);
  int max_a = 0;
  int max_a_ind = -1;
  int nex_max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a_num[a[i]] += 1;
    if (a[i] > max_a) {
      max_a = a[i];
      max_a_ind = i;
    } else if (a[i] > nex_max_a) {
      nex_max_a = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (max_a_ind != i || a_num[a[i]] > 1) {
      cout << max_a << endl;
    } else {
      cout << nex_max_a << endl;
    }
  }
  return 0;
}
