<?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, 0);

$map = [];
for ($i = 0; $n > $i; $i++) {
    $map[] = [];
}
#var_dump($ans);
foreach ($inputs as $input) {
    $index = $input[0] -1;
    $num   = $input[1];

    $map[$index][] = $num;
}
#var_dump($map);
$ans = '';
foreach ($map as $m) {
    $min = count($m) == 0 ? 0 :min($m);
    $ans .= $min;
}
#var_dump($ans);

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