#include <bits/stdc++.h>
using namespace std;
int a[20];
int n, k;
int main() {
  int n;
  int top1, top2;
  vector<int> vec(n);
  vector<int> vec_sorted(n);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  vec_sorted = vec;
  sort(vec_sorted.begin(), vec_sorted.end(), greater<int>());
  top1 = vec_sorted.at(0);
  top2 = vec_sorted.at(1);
  for (int i = 0; i < n; i++) {
    if (top1 == vec[i]) {
      cout << top2 << endl;
    } else {
      cout << top1 << endl;
    }
  }
  return 0;
}
