<?php
fscanf(STDIN, "%d %d", $N, $M);
$rangeStart = pow(10, (intval($N) - 1));
$rangeEnd = pow(10, intval($N)) - 1;

for ($m=0; $m<$M; $m++) {
    fscanf(STDIN, "%d %d", $position, $value);
    $hints[] = [
        'position' => intval($position)-1,
        'value' => (string)$value
    ];
}

$targets = range($rangeStart, $rangeEnd);
$suitable = array_filter($targets, function($num) use ($hints) {
    $result = true;
    $numStr = (string)$num;
    foreach($hints as $hint) {
        $result = $result & (substr($numStr, $hint['position'], 1) === $hint['value']);
        if (!$result) break;
    }
    return $result;
});
echo (!!$suitable ? min($suitable) : -1);
