<?php
$input = explode(' ', trim(fgets(STDIN)));
$digit = $input[0];
$hintCount = $input[1];
$rangeStart = pow(10, ($digit - 1));
$rangeEnd = pow(10, $digit) - 1;

$cnt = 0;
$hints = [];
while ($cnt < $hintCount) {
    $line = explode(' ', trim(fgets(STDIN)));
    $hints[] = [
        'position' => intval($line[0])-1,
        'value' => $line[1]
    ];
    $cnt++;
}

$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);
