#include <bits/stdc++.h>
using namespace std;
vector<int> a;
bool comp(int i, int j) { return a[i] > a[j]; }
int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  a.reserve(N);
  vector<int> indices(N);
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    indices[i] = i;
  }
  sort(indices.begin(), indices.end(), comp);
  for (int i = 0; i < N; ++i) {
    if (i != indices[0]) {
      cout << a[indices[1]] << endl;
    } else {
      cout << a[indices[0]] << endl;
    }
  }
  return 0;
}
