<?php

list($n, $m) = explode(' ', trim(fgets(STDIN)));

$digit = [];
for ($i = 1; $i <= $m; ++$i) {
    list($s, $c) = explode(' ', trim(fgets(STDIN)));
    if (isset($digit[$s]) && $c !== $digit[$s]) {
        echo '-1';
        exit;
    }
    $digit[$s] = $c;
}

if (isset($digit[1]) && $digit[1] == 0) {
    echo '-1';
    exit;
}

$answer = 0;
foreach ($digit as $s => $c) {
    $answer += ($c * 10 ** ($n - $s));
}

if (strlen((string)$answer) < $n) {
    $answer += (10 ** ($n - 1));
}

echo $answer;
