#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int(i) = 0; (i) < (n); (i)++) cin >> a[i];
  int tem = 0;
  int num = 0;
  int ans = 0;
  for (int(i) = 0; (i) < (n); (i)++) tem = max(tem, a[i]);
  for (int(i) = 0; (i) < (n); (i)++) {
    if (a[i] != tem)
      cout << tem << endl;
    else {
      a[i] = 0;
      for (int(i) = 0; (i) < (n); (i)++) {
        ans = max(ans, a[i]);
      }
      cout << ans << endl;
    }
  }
  return 0;
}
