#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    cin >> v[i];
  }
  int maxNum = *max_element((v).begin(), (v).end());
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int tmp = v[i];
    if (tmp == maxNum && count((v).begin(), (v).end(), maxNum) == 1) {
      v[i] = *min_element((v).begin(), (v).end());
      cout << *max_element((v).begin(), (v).end()) << endl;
      v[i] = tmp;
    } else {
      cout << maxNum << endl;
    }
  }
  return 0;
}
