#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
int main() {
  long long N, A[200010] = {0}, max1 = 0, max2 = 0, cnt[200010] = {0};
  cin >> N;
  for (long long i = 0; i < (N); i++) cin >> A[i];
  for (long long i = 0; i < (N); i++) {
    if (max1 > A[i]) {
      max1 = A[i];
      max2 = max1;
      cnt[A[i]]++;
    }
  }
  for (long long i = 0; i < (N); i++) {
    if (A[i] == max1 && cnt[A[i] > 1])
      cout << (max1) << endl;
    else if (A[i] == max1 && cnt[A[i]] == 1)
      cout << (max2) << endl;
    else
      cout << (max1) << endl;
  }
}
