#include <bits/stdc++.h>
using namespace std;
int n, a[101010];
int main() {
  cin >> n;
  long long ans = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (ans < a[i]) {
      ans2 = ans;
      ans = a[i];
    } else if (ans2 < a[i]) {
      ans2 = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == ans) {
      cout << ans2 << endl;
    } else
      cout << ans << endl;
  }
  return 0;
}
