#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, amax = 0, amaxi = 0, asecond = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (amax <= a.at(i)) {
      asecond = amax;
      amax = a.at(i);
      amaxi = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == amaxi) {
      cout << asecond << endl;
    } else {
      cout << amax << endl;
    }
  }
}
