let input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\s/);

const N = Number(input[0]);
const M = Number(input[1]);
const P = input.slice(2, 2 + 2 * M).filter((_, idx) => idx % 2 === 0).map(Number);
const Y = input.slice(3, 3 + 2 * M).filter((_, idx) => idx % 2 === 0).map(Number);

let index = [...Array(M)].map((_, idx) => idx + 1)

let dataframe = {"P": P, "Y": Y, "index": index};

dataframe.sort(function(a, b){
    if (a.Y < b.Y) return -1;
    if (a.Y > b.Y) return 1;
    return 0;
});

let number = [];
let counter = [...Array(N)].map((_, idx) => 0);

for (let i = 0; i < M; i++) {
    let city_num = dataframe[i].P;
    counter[city_num] += 1;
    tmp = 1000000 * city_num + counter[city_num];
    number.push(zeroPadding(tmp, 12));
}

let dataframe_new = {"number": number, "P": dataframe.P, "Y": dataframe.Y, "index": dataframe.index}

function zeroPadding(num, length) {
    return ('00000000000' + num).slice(-length);
}

dataframe_new.sort(function(a, b){
    if (a.index < b.index) return -1;
    if (a.index > b.index) return 1;
    return 0;
});

for (let i = 0; i < M; i++) {
    console.log(dataframe_new[i].number)
}