406998: GYM102672 F Arithmetic and blocks

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Arithmetic and blockstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Aurora has $$$n$$$ blocks. Each block has 6 sides, each side has a digit from $$$0$$$ to $$$9$$$ on it. The same digit on one block can appear multiple times.

Fairies taught Aurora some arithmetic and gave her a task  — to build numbers with blocks. Aurora can choose any subset of blocks, rotate them any side up and arrange them in any order to get the target number. Naturally, Aurora builds a number with no leading zeros.

Now, Aurora needs to learn how to count. Fairies intend to ask her to build positive integers in the ascending order. Blocks used for one number can be reused for another number. Please help the fairies to determine the minimum number which Aurora will never be able to build using a given set of blocks.

Input

The first line contains one integer $$$n$$$ — the number of blocks ($$$1 \le n \le 100\,000$$$).

Each of the next $$$n$$$ lines has 6 digits — $$$a_{i,1}, a_{i,2}, \ldots, a_{i,6}$$$ ($$$0 \le a_{i,j} \le 9$$$).

Output

Output the minimal number which Aurora won't be able to build.

ExamplesInput
2
012345
098765
Output
11
Input
3
123456
789012
345678
Output
90
Input
5
111111
222222
333333
444444
555555
Output
6

加入题单

算法标签: