#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N, MAX1 = 0, MAX2 = 0, check = 0;
  cin >> N;
  int A[N];
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
    if (MAX1 < A[i]) {
      MAX2 = MAX1;
      MAX1 = A[i];
    }
    if (MAX2 < A[i] && A[i] < MAX1) {
      MAX2 = A[i];
    }
    if (i != 0) {
      if (A[i - 1] == A[i]) check++;
    }
  }
  if (check == N - 1) {
    for (int i = 0; i < (N); i++) cout << MAX1 << endl;
    return 0;
  }
  for (int i = 0; i < (N); i++) {
    if (A[i] == MAX1) {
      cout << MAX2 << endl;
    } else {
      cout << MAX1 << endl;
    }
  }
  return 0;
}
