#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int a[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int Max1;
  int Max2;
  cin >> a[1];
  Max1 = Max2 = a[1];
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    if (Max1 == a[i]) {
      Max2 = a[i];
    } else {
      Max2 = Max1;
      Max1 = max(Max1, a[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == Max1) {
      cout << Max2 << endl;
    } else
      cout << Max1 << endl;
  }
  return 0;
}
