#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f = 0, s = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int i = 0; i < n; ++i) f = max(f, v[i]);
  for (int i = 0; i < n; ++i)
    if (v[i] != f) s = max(s, v[i]);
  for (int i = 0; i < n; ++i) {
    if (v[i] == f)
      cout << s << endl;
    else
      cout << f << endl;
  }
  return 0;
}
