#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  ll count = 0;
  int max = 0;
  int max2 = 0;
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
    if (max < data.at(i)) {
      max = data.at(i);
    } else if (max2 < data.at(i)) {
      max2 = data.at(i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (data.at(i) == max) {
      cout << max2 << endl;
    } else {
      cout << max << endl;
    }
  }
}
