#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  int tmp = a[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != a[n - 1]) {
      tmp = a[i];
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (b[i] != a[n - 1]) {
      cout << a[n - 1] << endl;
    } else {
      cout << tmp << endl;
    }
  }
  return 0;
}
