<?php
    fscanf(STDIN,"%d %d",$n,$m);
    $ans = array_fill(1,$n,0);
    $flag = 0;
    $higher = 4;
    $one = 0;
    if($m === 0){
        $flag = 2;
        $one = 1;
    }
    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;
        }
        if($n === 3 && ($s === 2 || $s === 3) && $c === 0){
            $flag = 2;
            if($higher > $s){
                $higher = $s;
                $one = $s -1;
            }
            continue;
        }

        if($n === 2 && $s === 2 && $c === 0){
            $flag = 2;
            if($higher > $s){
                $higher = $s;
                $one = $s -1;
            }
            continue;
        }

        $ans[$s] = $c;
    }
    
    if($flag === 0 || ($flag === 2 && $ans[1] !== 0) || ($flag === 2 && $n ===3 && $ans[2] !== 0)){
        echo (int)implode("",$ans).PHP_EOL;
    }else if($flag === 2){
        $ans[$one] = 1;
        echo (int) implode("", $ans) . PHP_EOL;
    }else{
        echo "-1".PHP_EOL;
    }
?>