#include <bits/stdc++.h>
using namespace std;
int compare(int a, int b) { return a > b; }
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int max = arr[0];
  int index;
  for (int i = 0; i < n; i++) {
    if (arr[i] > max) {
      max = arr[i];
      index = i;
    }
  }
  int secmax = -1;
  for (int i = 0; i < n; i++) {
    if (arr[i] > secmax && i != index) {
      secmax = arr[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != index) {
      cout << max << '\n';
    } else {
      cout << secmax << '\n';
    }
  }
  cerr << "Time elapsed" << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
  return 0;
}
