#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ma, ma2;
  ma = 1;
  ma2 = 1;
  int hold[N];
  for (int i = 0; i < (int)(N); i++) {
    cin >> hold[i];
    if (i == 0) {
      ma = hold[i];
      continue;
    }
    if (i == 1) {
      ma2 = min(ma, hold[i]);
      ma = max(ma, hold[i]);
      continue;
    }
    if (max(ma, hold[i]) > ma || ma == hold[i]) {
      ma2 = ma;
      ma = hold[i];
    }
    if (max(ma2, hold[i]) > ma2) {
      ma2 = hold[i];
    }
  }
  for (int i = 0; i < (int)(N); i++) {
    if (hold[i] == ma)
      cout << ma2 << endl;
    else
      cout << ma << endl;
  }
}
