#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int N;
  cin >> N;
  long long int arr[N];
  long long int mx = 0;
  for (long long int i = 0; i < N; i++) {
    cin >> arr[i];
    mx = max(mx, arr[i]);
  }
  long long int dummy[N];
  std::copy(arr, arr + N, dummy);
  sort(arr, arr + N);
  bool first = true;
  for (long long int i = 0; i < N; i++) {
    if (mx == dummy[i] && first) {
      cout << arr[1] << "\n";
      first = false;
    } else
      cout << mx << "\n";
  }
  return 0;
}
