<?php

fscanf(STDIN, "%d %d", $n, $m);
$s_arr = [];
$c_arr = [];
for ($i = 0; $i < $m; ++$i) {
    $inputs = explode(' ', trim(fgets(STDIN)));
    $s_arr[] = $inputs[0];
    $c_arr[] = $inputs[1];
}

$results = array_fill(0, $n, 0);
$exists = true;

for ($i = 0; $i < $m; ++$i) {
    if ($results[$s_arr[$i]] == $c_arr[$i]  && $results[$s_arr[$i] - 1] != 0) {
        $exists = false;
        break;
    }
    $results[$s_arr[$i] - 1] = $c_arr[$i];
}

if (!$exists) {
    echo -1;
} else {
    $num =  (int) implode('', $results);
    if (strlen($num) !== $n) {
        echo -1;
    } else {
        echo $num;
    }
}

