#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n;
  s = n;
  vector<int> a(n);
  vector<int> b(s);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  for (int i = 0; i < n; i++) {
    for (int x = 0; x < n - 1; x++) {
      for (int y = x + 1; y < n; y++) {
        if (a.at(y) > a.at(x)) {
          int m = a.at(y);
          a.at(y) = a.at(x);
          a.at(x) = m;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (b.at(i) == a.at(0)) {
      cout << a.at(1) << endl;
    }
    if (b.at(i) != a.at(0)) {
      cout << a.at(0) << endl;
    }
  }
  return 0;
}
