use strict;
use warnings;
use List::Util 'all';

my ($N, $M) = glob(<>);
my @SC = ();

for (my $i = 0; $i < $M; $i++) {
    my ($s, $c) = glob(<>);
    $SC[$i] = [ $s, $c ];
}

for (my $i = 0; $i < 1000; $i++) {
    if (length($i) == $N) {
        if (all {substr($i, $_->[0] - 1, 1) == $_->[1]} @SC) {
            print $i;
            exit;
        }
    }
}

print -1;