#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T> >;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int array[N];
  for (int i = 0; i < N; i++) {
    cin >> array[i];
  }
  int max = 0;
  int number = 0;
  for (int i = 0; i < N; i++) {
    if (max < array[i]) {
      max = array[i];
      number = i;
    } else
      max = max;
  }
  int max2 = 0;
  for (int i = 0; i < N; i++) {
    if (max2 < array[i] && array[i] < max)
      max2 = array[i];
    else
      ;
  }
  for (int i = 0; i < N; i++) {
    if (i == number)
      cout << max2 << endl;
    else
      cout << max << endl;
  }
}
