Time limit
2s
Memory limit
128 MB
An encryption key can be divided among several people instead of being stored as one piece. The key is split into N digit strings called shares.
A new encryption algorithm uses a very long decimal integer as its key. The key must start with a nonzero digit, and every share must be used exactly once. The order of the shares is determined by this rule: among all concatenations that use every share, the encryption key is the smallest valid decimal integer. Any concatenation that starts with 0 is invalid.
Given N shares, restore the encryption key.
The first line contains the number of shares N (1 <= N <= 100).
The next line contains N digit strings. Each share has length at most 5, and a share may start with 0.
Print the restored encryption key on one line.
If no key satisfies the conditions, print INVALID.