#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];
  vector<int> b = a;
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    int ans = b[0];
    if (b[0] == a[i]) ans = b[1];
    cout << ans << endl;
  }
  return 0;
}
