#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i, j, k, t, l;
  cin >> n;
  int a[n + 5];
  map<long long, long long> m;
  vector<long long> v;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (m[a[i]] == 0) {
      v.push_back(a[i]);
      m[a[i]]++;
    }
  }
  sort(v.begin(), v.end());
  if (v.size() == 1) {
    for (i = 0; i < n; i++) cout << v[0] << endl;
  } else {
    for (i = 0; i < n; i++) {
      if (a[i] == v[v.size() - 1])
        cout << v[v.size() - 2] << endl;
      else
        cout << v[v.size() - 1] << endl;
    }
  }
}
