#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort((b).begin(), (b).end());
  for (int i = 0; i < n; i++) {
    int mx = *max_element(b.begin(), b.end());
    if (mx == a[i]) {
      cout << b[n - 2] << "\n";
    } else
      cout << mx << "\n";
  }
  return 0;
}
