#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> V(n);
  for (int k = 0; k < n; k++) {
    cin >> V.at(k);
  }
  int ans = *max_element(V.begin(), V.end());
  for (int i = 0; i < n; i++) {
    if (ans == V.at(i)) {
      int y = V.at(i);
      V.at(i) = -1;
      int x = *max_element(V.begin(), V.end());
      cout << x << endl;
      V.at(i) = y;
    } else {
      cout << ans;
    }
  }
}
