<?php
  $NM = explode(' ', trim(fgets(STDIN)));
  $N = $NM[0];
  $M = $NM[1];

  $scs = [];
  for ($i = 0; $i < $M; $i++) {
    $scs[$i] = explode(' ', trim(fgets(STDIN)));
  }

  $min = pow(10, $N-1);
  $max = pow(10, $N);
  for ($min; $min < $max; $min++) {
    $res = true;
    for ($j = 0; $j < $M; $j++) {
      $s = $scs[$j][0] - 1;
      $c = $scs[$j][1];
      $res = $res && substr($min, $s, 1) === $c;
    }
    
    if ($res) {
      echo $min;
      return;
    }
  }
  
  echo '-1';
