#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  int max1 = -1;
  int max2 = -1;
  for (int i = 0; i < n; i++) {
    if (max1 == -1) {
      max1 = 0;
    } else if (a[i] > a[max1]) {
      max1 = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (max2 == -1) {
      max2 = 0;
    } else if (a[i] > a[max2] and i != max1) {
      max2 = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == max1) {
      cout << a[max2] << "\n";
    } else {
      cout << a[max1] << "\n";
    }
  }
}
