#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(15);
  cout << fixed;
  int n = 0;
  cin >> n;
  vector<int> vec(n);
  map<int, int> mp;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec[i] = x;
    mp[x]++;
    mx = max(mx, vec[i]);
  }
  int two = mx - 1;
  while (mp.find(two) == mp.end() && two > 0) two--;
  for (int i = 0; i < n; i++) {
    if (mp.count(mx) > 1) {
      cout << mx << '\n';
    } else {
      if (vec[i] == mx)
        cout << two << '\n';
      else
        cout << mx << '\n';
    }
  }
  return 0;
}
