#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N];
  int largest = INT_MIN;
  int second = INT_MIN;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i == 0) {
      largest = A[i];
      second = A[i];
    } else if (largest <= A[i]) {
      second = largest;
      largest = A[i];
    } else if (second <= A[i]) {
      second = A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    int ans;
    if (A[i] == largest) {
      ans = second;
    } else {
      ans = largest;
    }
    cout << ans << endl;
  }
  return 0;
}
