#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
using ll = long long;
const int mod = 1000000007;
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
bool Array_check(ll y, ll x, ll d, ll w) {
  if (x < 0 || x >= w || y < 0 || y >= d) {
    return false;
  } else {
    return true;
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  int nm = 0;
  int m = 0;
  for (int i = 0; i < (n); i++) {
    if (a[i] > m) {
      m = a[i];
    } else if (a[i] > nm) {
      nm = a[i];
    }
  }
  for (int i = 0; i < (n); i++) {
    if (m != a[i]) {
      cout << m;
    } else {
      cout << nm;
    }
  }
}
