#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, l = 0, h, arr[200005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    arr[i] = x;
    if (x >= l) {
      h = l;
      l = x;
    }
  }
  for (int j = 0; j < n; j++) {
    if (arr[j] == l) {
      cout << h << endl;
    } else {
      cout << l << endl;
    }
  }
}
