#include <bits/stdc++.h>
using namespace std;
int gcd(int A, int B) {
  if (!B) return A;
  return gcd(B, A % B);
}
int a[200005];
int b[200005];
int main() {
  int n;
  cin >> n;
  map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    b[i] = a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    if (a[i] == b[n - 1] && cnt[a[i]] == 1)
      cout << b[n - 2] << endl;
    else
      cout << a[i] << endl;
  }
}
