#d21002. 最小整数

最小整数

Smallest Integer

Problem Description

You are given the frequency of each digit 0∼90\sim 9: digit ii appears aia_i times. Using all the given digits, form an integer that satisfies the following conditions and is as small as possible:

  • All given digits must be used.
  • The leading digit cannot be 00, unless the result is the single digit 00.
  • No two adjacent digits may be the same.

Find the smallest integer that can be formed.

Input Format

Input 1010 integers a0,a1,…,a9a_0, a_1, \dots, a_9 (0≤ai≤1050\le a_i\le 10^5), the frequencies of each digit. It is guaranteed that 1≤∑i=09ai≤1051\le \sum_{i=0}^{9} a_i \le 10^5.

Output Format

Output one line containing an integer: the smallest integer that can be formed; if no such integer exists, output -1.

Sample Input

2 0 1 0 0 1 0 2 0 0

Sample Output

205707