import java.util.*

fun main(args: Array<String>) {
    val numbers = Numbers()
    (1..readLine()!!.toInt()).map { readLine()!!.toInt() }.forEach(numbers::addValue)
    numbers.printValue()
}

data class Numbers(private val digits: MutableMap<Int, DigitNumbers> = TreeMap()) {

    fun addValue(value: Int) {
        val digit = value.toString().length
        addValue(digit, value)
    }

    private fun addValue(digit: Int, value: Int) {
        val digitNumbers = digits[digit] ?: DigitNumbers()
        digitNumbers.addIfNeeded(value)
        digits[digit] = digitNumbers
    }


    fun printValue() {
        val values = mutableListOf<Int>()
        digits.values.forEach {
            values.addAll(it.values)
            if (values.size >= 3) {
                return@forEach
            }
        }

        println(values.flatMap { v -> values.filter { v != it }.map { "$it$v".toInt() }.toList() }.sorted()[2])
    }
}

data class DigitNumbers(private val numbers: MutableList<Int> = mutableListOf()) {

    companion object {
        private const val LIMIT_VALUE = 3
    }

    val values: List<Int> get() = numbers

    fun addIfNeeded(value: Int) {
        if (numbers.size <= LIMIT_VALUE) {
            numbers.add(value)
        } else if (numbers.max()!! >= value) {
            numbers.add(value)
            numbers.sort()
            numbers.removeAt(numbers.size - 1)
        }
    }
}

