#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int max_1st, max_2nd;
  if (a[n - 1] > a[n - 2]) {
    max_1st = a[n - 1];
    max_2nd = a[n - 2];
  } else {
    max_1st = a[n - 2];
    max_2nd = a[n - 1];
  }
  for (int i = 0; i < (n - 2); ++i) {
    if (a[i] > max_1st) {
      max_2nd = max_1st;
      max_1st = a[i];
    } else if (a[i] > max_2nd) {
      max_2nd = a[i];
    }
  }
  for (int i = 0; i < (n); ++i) {
    if (a[i] > max_1st) {
      cout << max_2nd << endl;
    } else {
      cout << max_1st << endl;
    }
  }
  return 0;
}
