#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
void solve() {
  int n;
  cin >> n;
  int num1, val1 = 0, num2, val2;
  for (int64_t i = (0); i < (n); i++) {
    int a;
    cin >> a;
    if (a > val1) {
      val2 = val1;
      num2 = num1;
      val1 = a;
      num1 = i;
    }
    if (a < val1 && a > val2) {
      val2 = a;
      num2 = i;
    }
  }
  for (int64_t i = (0); i < (n); i++) {
    if (i == num1 && val2 != 0)
      cout << val2 << endl;
    else
      cout << val1 << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
