my ($N, $M) = glob<>;
%foo;
for($i=0;$i<$M;$i++){
    ($s,$c) = glob<>;
    if( ($s == 1 && $c == 0) || grep{$_ == $s && $foo{$_} != $c}keys(%foo)){
        print "-1";
        goto end;
    }
    $foo{$s} = $c;
}
$r = "";
for($j=0;$j<$N;$j++){
    $f = $foo{$j+1};
    if($r eq "" && $f == 0){
        print "-1";
        goto end;
    }
    if($r eq ""){
        $r = $r . ($f ? "$f" : "");
    }else{
        $r = $r . ($f ? "$f" : "0");
    }
}
print $r eq "" ? "0" : $r;
end:{

}