#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
bool vis[N];
vector<int> adj[N];
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v;
  long long int highest = 0;
  long long int pos = 0;
  for (long long int i = 0; i < n; i++) {
    long long int c;
    cin >> c;
    v.push_back(c);
    if (highest < c) {
      highest = c;
      pos = i;
    }
  }
  long long int shighest = 0;
  ;
  v.erase(v.begin() + pos);
  for (long long int i = 0; i < n; i++) {
    long long int c = v[i];
    if (shighest < c) {
      shighest = c;
    }
  }
  for (int i = 0; i < n; i++) {
    if (pos == i) {
      cout << shighest << '\n';
    } else
      cout << highest << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
}
