#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l, N, i = 0;
  cin >> N;
  int vec[N];
  int g_max = 0;
  int max = 0;
  int sec_index = 0;
  int sec_max = 0;
  while (cin >> l) {
    vec[i] = l;
    if (max < l) {
      sec_max = max;
      max = l;
      g_max = i;
    }
    i++;
  }
  for (i = 0; i < N; i++) {
    max = 0;
    if (i == g_max) {
      max = sec_max;
    } else {
      max = vec[g_max];
    }
    cout << max << "\n";
  }
}
