#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  pair<int, int> max = (0, -1);
  for (int i=0; i<n; i++) {
    cin >> vec.at(i);
    if (max.first < vec.at(i)) {
      max.first = vec.at(i);
      max.second = i;
    }
  }
  sort(vec.begin(), vec.end());
  for (int i=0; i<n; i++) {
    if (i == max.second) cout << vec.at(1) << endl;
    else cout << max.first << endl;
  }
}