<?php
    fscanf(STDIN,"%d %d",$n,$m);
    $ans = array_fill(1,$n,0);
    $flag = 0;
    for($i = 0; $i < $m; $i++){
        fscanf(STDIN, "%d %d", $s, $c);
        if($ans[$s] !== 0 && $ans[$s] !== $c){
            $flag = 1;
            break;
        }
        if ($n !== 1 && $s === 1 && $c === 0) {
            $flag = 1;
            break;
        }
        $ans[$s] = $c;
    }
    
    if($flag === 0){
        echo (int)implode("",$ans).PHP_EOL;
    }else{
        echo "-1".PHP_EOL;
    }
?>