#include <bits/stdc++.h>
using namespace std;
const int INF = 1000100100;
int main() {
  long long n, x, k, max = 0, ma = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    if (max < x) {
      ma = max;
      max = x;
      k = i;
    } else if (ma < x) {
      ma = x;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (i == k)
      cout << ma;
    else
      cout << max;
  }
}
