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