<?php
  
  list($n, $m) = explode(" ", trim(fgets(STDIN)));

  $array_s = [];

  if($m == 0){
    if($n == 1){
      echo "0";
      exit;
    }else{
      echo "-1";
      exit;
    }
  }
  for($i=0;$i<$m;$i++){
    list($s, $c) = explode(" ", trim(fgets(STDIN)));
    if($n != 1 && $s == 1 && $c == 0){
      echo "-1";
      exit;
    }
    if(isset($array_s[$s])){
      if($array_s[$s] != $c){
        echo "-1";
        exit;
      }
    }
    $array_s[$s] = $c;
  }
  
  $anser = [];
  for($i=1;$i<=$n;$i++){
    if(isset($array_s[$i])){
      echo $array_s[$i];      
    }else{
      if($i==1){
        echo "1";
      }else{
        echo "0";
      }
    }
  }
