<?php

fscanf(STDIN, "%d %d", $n, $m);
$s_arr = [];
$c_arr = [];

$tmp_arr = [];
for ($i = 0; $i < $m; ++$i) {
    $inputs = explode(' ', trim(fgets(STDIN)));

    $tmp_arr[$inputs[0] - 1][] = $inputs[1];
}

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

foreach ($tmp_arr as $digit => $tmp) {

    $tmp = array_unique($tmp);
    if (count($tmp) !== 1) {
        $exists = false;
        break;
    }

    $results[$digit] = $tmp[0];
}


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