#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  long long mx = 1, mx2 = 0;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (mx < a[i]) {
      mx2 = mx;
      mx = a[i];
    } else if (mx2 < a[i] <= mx) {
      mx2 = a[i];
    }
  }
  for (long long j = 0; j < n; j++) {
    if (a[j] == mx) {
      cout << mx2 << endl;
    } else {
      cout << mx << endl;
    }
  }
  return 0;
}
