#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i).first;
    a.at(i).second = i;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a.at(0).second != i) {
      cout << a.at(0).first << endl;
    } else {
      cout << a.at(1).first << endl;
    }
  }
}
