#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  int max1 = a[0], max2 = a[0];
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] > max1) {
      max1 = a[i];
    } else if (a[i] > max2 && a[i] <= max1) {
      max2 = a[i];
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] != max1) {
      cout << max1 << endl;
    } else {
      cout << max2 << endl;
    }
  }
}
