#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma warning(disable : 4996)
const int maxn = 1000 * 100;
const int maxa = 1000 * 1000 * 1000 + 7;
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int t, n, m, T, d;
int main() {
  int i, j;
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  while (cin >> n) {
    int max1 = 0, max2 = 0, a[maxn];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      int& tmp = a[i];
      if (tmp > max1) {
        max2 = max1;
        max1 = tmp;
      } else if (tmp > max2) {
        max2 = tmp;
      }
    }
    for (int i = 0; i < (n); ++i) {
      if (a[i] == max1)
        cout << max2;
      else
        cout << max1;
      cout << "\n";
    }
  }
  return 0;
}
