#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int top = 0;
  int sec = 0;
  int top_num = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    a.insert(a.begin() + i, b);
    if (a[i] > top) {
      sec = top;
      top = a[i];
      top_num = i;
    } else if (a[i] > sec) {
      sec = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (top_num != i) {
      cout << top;
    } else {
      cout << sec;
    }
  }
}
