#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c, mx = 0, mx2, ch = 0;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    c = vec.at(i);
    if (mx == c) ch++;
    mx = max(mx, c);
  }
  for (int i = 0; i < n; i++) {
    c = vec.at(i);
    if (c != mx && mx2 < c) mx2 = c;
  }
  if (mx2 == 0) mx2 = mx;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) == mx && ch == 0)
      cout << mx2 << endl;
    else
      cout << mx << endl;
  }
}
