#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
int s[N], f[N];
int main(void) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s[i], f[i] = s[i];
  sort(f, f + n, greater<int>());
  int a = f[0], b = f[1];
  for (int i = 0; i < n; ++i) {
    cout << (s[i] == a ? a : b) << endl;
  }
  return 0;
}
