<?php

fscanf(STDIN, "%d %d", $n, $m);
$inputs = [];
for ($i = 0; $m > $i; $i++) {
    $input = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $inputs[] = $input;
}

$ans = array_pad([], $n, '-');

#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    if (isset($ans[$index])) {
        if ($ans[$index] != '-' && $ans[$index] != $num) {
            echo -1;
            exit;
        }
        $ans[$index] = $num;
    }
}
#var_dump($ans);

if ($n > 1 && $ans[0] == '-') $ans[0] = 1;
$ans = str_replace('-', '0',$ans);

$x = intval(join('', $ans));
#var_dump($x);
$len = strlen($x);
if ($len == $n) {
    echo $x;
} else {
    echo -1;
}
