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