Arithmetic and Dice
Time limit2sMemory limit1024 MB
Given n dice with digits 0 to 9 on their faces, find the smallest natural number that cannot be built, where dice are reusable across numbers.
Statement
Aurora has dice. Each die has six faces, and each face shows a digit from to . The digits on one die may repeat.
The fairies decided to teach Aurora arithmetic by giving her a task: build numbers from the dice. Aurora may pick any set of dice, turn each chosen die to any face, and arrange the dice in any order to form the desired number. Aurora never builds a number with leading zeros.
To help Aurora practice, the fairies want her to build the natural numbers one by one in increasing order. The dice used to build one number can be used again for the next numbers. Help the fairies find the smallest natural number that Aurora cannot build with the given dice.
Input
The first line contains an integer , the number of dice ().
Each of the next lines contains a string of six digits (), the digits on the faces of die .
Output
Print the smallest natural number that Aurora cannot build.