function main(input) {
    const args = input.split('\n')
    const args0 = args[0].split(' ')
    const sumPrefecture = +args0[0]
    const sumCity = +args0[1]
    args.shift()

    const cityList = args.map(item => {
        const tmpArry = item.split(' ')
        const belongPrefecture = tmpArry[0]
        const barthYear = tmpArry[1]
        return {pre: +belongPrefecture, year: +barthYear}
    })

    const preList = {}
    for (let i = 1; i <= sumPrefecture; i++) {
        preList[i.toString().padStart(6, '0')] = cityList.filter(item => {
            return item.pre == i
        }).map(item => {
            return item.year
        }).sort(function (a, b) {
            return a - b
        })
    }

    Object.keys(preList).forEach((key, index) => {
        for (let [item, index2] of preList[key].entries()) {
            console.log(key+(+item + 1).toString().padStart(6,'0'))
        }

    })


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));