<?php
fscanf(STDIN, '%d %d', $len, $cnt);
$rules = [];
for ($i=0; $i < $cnt; $i++) { 
    fscanf(STDIN, '%d %d', $tar, $val);
    $check = array_keys($rules, $val);
    if (array_key_exists($tar, $rules) && !in_array($tar, $check)) {
        echo (-1)."\n";
        exit;
    }
    $rules[$tar] = $val;
}

for ($i=10**($len-1); $i < 10**$len; $i++) {
    $nums = array_map('intval', str_split($i)); 
    $flag = true;
    foreach ($rules as $key => $value) {
        if ($nums[$key-1] !== $value) {
            $flag = false;
            break;
        }
    }
    if ($flag) {
        echo $i."\n";
        exit;
    }
}
echo (-1)."\n";