use strict;
use warnings;

my ($n, $m);
{
  my $in = <STDIN>;
  ($n, $m) = split(" ", $in);
}
my (@s, @c);
{
  for (my $i=0; $i<$m; $i++) {
    my $in = <STDIN>;
    ($s[$i], $c[$i]) = split(" ", $in);
  }
}

for (my $i=0; $i<100000; $i++) {
  my $ans = 0;
  next if length($i) != $n;
  for (my $j=0; $j<$m; $j++) {
    if (substr($i, $s[$j]-1, 1) eq $c[$j]) {
      $ans++;
    }
    if ($ans==$m) {
      print $i, "\n";
      exit;
    }
  }
}
print "-1\n";