#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll solve(vi B, bool need, bool can9) {
  if (B.empty()) { return need; }
  if (sz(B) == 1) {
    if (B[0] == 1) return 10;
    ll ans = 0;
    rep (d, 1, 10) if (B[0] >> d & 1) {
      ans = ans * 10 + d;
      if (B[0] & 1) {
        B[0] ^= 1;
        ans *= 10;
      }
    }
    return ans;
  }
  ll ans = 102345678900000ll;
  rep (d, 0, 10) {
    if (sz(B) <= 2 and d == 9 and not can9) continue;
    vi nB(sz(B) / 10 + 2);
    rep (i, 0, sz(B)) {
      int j = (d + i) / 10, k = (d + i) % 10;
      nB[j] |= (B[i] & (~(1 << k)));
    }
    while (not nB.empty() and nB.back() == 0) nB.pop_back();
    ans = min(ans, solve(nB, d == 0 and (B[0] & 1), not (sz(B) <= 2 and d == 9)) * 10 + d);
  }
  return ans;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int K;
  cin >> K;
  vi B(K);
  rep (i, 0, K) {
    int a;
    cin >> a;
    B[i] = (1 << a);
  }
  
  cout << solve(B, false, true) << '\n';
  return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |