#include <bits/stdc++.h>
using namespace std;
using vec = vector<long long>;
using mat = vector<vec>;
using Pii = pair<long long, long long>;
using PiP = pair<long long, Pii>;
using PPi = pair<Pii, long long>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;
template <typename T>
void readv(vector<T> &a) {
  for (long long i = (0); i < (a.size()); i++) cin >> a[i];
}
void readv_m1(vector<int> &a) {
  for (long long i = (0); i < (a.size()); i++) {
    cin >> a[i];
    a[i]--;
  }
}
long long mod = 1000000007;
int main() {
  long long N;
  cin >> N;
  vec A(N);
  long long maxi = -1;
  long long maxA = -1;
  long long nextA = -1;
  for (long long i = (0); i < (N); i++) {
    cin >> A[i];
    if (A[i] > maxA) {
      maxi = i;
      nextA = maxA;
      maxA = A[i];
    }
  }
  for (long long i = (0); i < (N); i++) {
    if (i == maxi) {
      cout << nextA << endl;
    } else {
      cout << maxA << endl;
    }
  }
  return 0;
}
