#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, max = 0, max2 = 0, k;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    a.push_back(k);
    if (a[max] <= a[i]) {
      if (i) {
        max2 = max;
        max = i;
      }
    } else if (a[max2] <= a[i]) {
      max2 = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == max) {
      cout << a[max2] << endl;
    } else {
      cout << a[max] << endl;
    }
  }
  return 0;
}
