#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n;
  cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  int max_i = 0;
  int second_i = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] >= a[max_i]) {
      second_i = max_i;
      max_i = i;
    } else if (a[i] >= a[second_i]) {
      second_i = i;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (i != max_i) {
      cout << a[max_i] << endl;
    } else {
      cout << a[second_i] << endl;
    }
  }
  return 0;
}
