<?php
define('MOD', 10**9+7);

//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$M) = explode(" ",trim(fgets(STDIN)));
//$a[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}
//

$res = str_pad("",$N,"-");
for($i=0;$i<$M;$i++) {
  list($s,$c) = explode(" ",trim(fgets(STDIN)));
  if ($res[$s-1]!="-" && $res[$s-1]!=$c) {
    printf("-1\n");exit;
  }
  $res[$s-1]=$c;
}
if ($res[0]=="-") $res[0]=1;
$res = str_replace("-","0",$res);
if ((int)$res==0 || strlen((String)(int)$res)!=$N) {
  $res = -1;
}
printf("%d\n",$res);
