#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f, g, h, n;
vector<int> x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    x.push_back(a);
  }
  d = *max_element(x.begin(), x.end());
  for (int i = 0; i < n; i++) {
    if (x[i] != d) {
      cout << d << endl;
    } else {
      c = x[i];
      x[i] = 0;
      cout << *max_element(x.begin(), x.end()) << endl;
      x[i] = c;
    }
  }
}
