#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int>& a, pair<int, int>& b) { return (a.first >= b.first); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > v(n);
  int A[n];
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    v[i] = make_pair(A[i], i);
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < n; ++i) {
    if (v[0].second == i)
      cout << v[1].first << endl;
    else
      cout << v[0].first << endl;
  }
  return 0;
}
