#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  long long int max_no = v[0];
  long long int max_no2 = v[0];
  long long int num = 0;
  for (long long int i = 1; i < n; i++) {
    if (max_no <= v[i]) {
      max_no2 = max_no;
      max_no = v[i];
      num = i;
    } else if (max_no > v[i] && max_no2 < v[i]) {
      max_no2 = v[i];
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (i == num) {
      cout << max_no2 << endl;
    } else {
      cout << max_no << endl;
    }
  }
}
