#include <bits/stdc++.h>
using namespace std;
vector<int> v[200009];
int main() {
  int n, i, j, mx1 = 1e9, mx2 = 1e9;
  scanf("%d", &n);
  int a[n], b[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b, b + n);
  mx1 = b[n - 1];
  mx2 = mx1;
  for (i = n - 2; i >= 0; i--) {
    if (b[i] < mx1) {
      mx2 = b[i];
      break;
    }
  }
  for (i = 0; i < n; i++) {
    if (a[i] != mx1)
      cout << mx1 << endl;
    else if (a[i] == mx1)
      cout << mx2 << endl;
  }
}
