fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var rank = IntArray(n+1){1}
    val cities=(1..m).map {
        val (p, y) = readLine()!!.split(" ").map { it.toInt() }
        return@map City(it, p, y)
    }.sortedBy { it.year }
            .map { Pair(it,rank[it.pref]++) }
            .sortedBy { it.first.no }
            .fold(StringBuilder()) { acc, pair ->
                acc.append("%06d%06d\n".format(pair.first.pref,pair.second) )
            }.let { println(it) }
}

class City(val no:Int, val pref:Int, val year:Int)
