#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n), s(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s[i] = a[i];
  }
  sort(s.begin(), s.end());
  int max = s.back(), max2 = 0, i = n - 1;
  while (--i >= 0) {
    if (s[i] != max) {
      max2 = s[i];
      break;
    }
  }
  if (max2 == 0) max2 = max;
  for (int i : a)
    if (i == max)
      cout << max2 << endl;
    else
      cout << max << endl;
}
