#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  int max = 0;
  int sec = 0;
  int maxCnt, secCnt;
  int tmp = 0;
  cin >> num;
  vector<int> vec(num);
  for (int i = 0; i < num; i++) {
    cin >> vec.at(i);
    if (i == 0) {
      max = vec.at(i);
      maxCnt = i;
    }
    if (vec.at(i) > max) {
      sec = max;
      secCnt = maxCnt;
      max = vec.at(i);
      maxCnt = i;
    } else if (vec.at(i) > sec) {
      sec = vec.at(i);
      secCnt = i;
    }
  }
  for (int i = 0; i < num; i++) {
    if (i == maxCnt) {
      cout << sec << endl;
    } else {
      cout << max << endl;
    }
  }
}
