#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a;
  int temp;
  for (int i = 0; i < (n); ++i) {
    cin >> temp;
    a.push_back(temp);
  }
  int no1 = a[0];
  int no2 = a[0];
  int no1index = 0;
  int no2index = 0;
  for (int i = 0; i < (n); ++i) {
    if (no1 < a[i]) {
      no2 = no1;
      no2index = no1index;
      swap(no1, a[i]);
      temp = i;
      swap(no1index, temp);
    }
    if (no2 < a[i]) {
      no2 = a[i];
      no2index = temp;
    }
  }
  vector<int> ans(n, no1);
  ans[no1index] = no2;
  for (int i = 0; i < (n); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
