#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max1 = 0, max2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  max1 = max2 = a[0];
  for (int i = 0; i < n; i++) {
    if (max1 < a[i]) {
      max2 = max1;
      max1 = a[i];
    } else if (max2 < a[i]) {
      max2 = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max1) {
      cout << max2 << "\n";
    } else {
      cout << max1 << "\n";
    }
  }
  return 0;
}
