#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int inf = 1e9;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const long long MAX = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), sort_a(n);
  int input;
  int maximum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> input;
    a[i] = input;
    sort_a[i] = input;
    maximum = max(maximum, input);
  }
  sort((sort_a).begin(), (sort_a).end());
  int second_maximum = sort_a[1];
  for (int i = 0; i < n; ++i) {
    if (a[i] == maximum)
      cout << second_maximum << endl;
    else
      cout << maximum << endl;
  }
  return 0;
}
