#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
using namespace std;
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = (power(x, y / 2)) % 1000000007;
  if (y % 2 == 0)
    return ((temp % 1000000007) * temp) % 1000000007;
  else
    return ((x * temp % 1000000007) * temp) % 1000000007;
}
long long inv(long long x) {
  return (power(x, 1000000007 - 2) + 1000000007) % 1000000007;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second > b.second;
}
int32_t main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, maxer = INT_MIN, maxer2 = INT_MIN;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] > maxer) {
      maxer2 = max(maxer2, maxer);
      maxer = arr[i];
    } else
      maxer2 = max(maxer2, arr[i]);
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] == maxer)
      cout << maxer2 << '\n';
    else
      cout << maxer << '\n';
  }
  return 0;
}
