use proconio::{input, fastout};

fn find(arr: &Vec<(isize, isize)>) -> isize {
    'outer: for i in 100..1000 {
        for (s, c) in arr {
            let digit = match s {
                3 => i%10,
                2 => i/10,
                1 => i/100,
                _ => unreachable!(),
            };
            if digit != *c { continue 'outer; }
        }
        return i;
    }
    -1
}

#[fastout]
fn main() {
    input!{
        n: isize, m: isize,
        sc: [(isize, isize); m],
    }

    println!("{}", find(&sc));
}
