#include <bits/stdc++.h>
using namespace std;
long long int num_1 = 0;
long long int num_2 = 0;
void max_dp(vector<long long int> v, int n) {
  vector<long long int> dp(n + 1);
  vector<long long int> dp_2(n + 1);
  dp[1] = v[0];
  for (int i = 2; i <= n; ++i) {
    dp[i] = max(dp[i - 1], v[i - 1]);
  }
  num_1 = dp[n];
  for (int i = 0; i < n; ++i) {
    if (num_1 == v[i]) {
      v[i] = 0;
      continue;
    }
  }
  dp_2[1] = v[0];
  for (int i = 2; i <= n; ++i) {
    dp_2[i] = max(dp_2[i - 1], v[i - 1]);
  }
  num_2 = dp_2[n];
}
int main() {
  long long int n = 0;
  cin >> n;
  vector<long long int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  max_dp(v, n);
  for (int i = 0; i < n; ++i) {
    if (num_1 == v[i]) {
      cout << num_2 << endl;
    } else {
      cout << num_1 << endl;
    }
  }
  return 0;
}
