use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let mut cond = vec![vec![]; n];
    for _ in 0..m {
        let s: usize = it.next().unwrap().parse().unwrap();
        let c: usize = it.next().unwrap().parse().unwrap();
        cond[n - s].push(c);
    }
    let valid = |x: usize| -> bool {
        let mut y = x;
        let mut ok = true;
        for cond in cond.iter() {
            for &d in cond.iter() {
                if y % 10 != d || y == 0 {
                    ok = false;
                }
            }
            y /= 10;
        }
        ok
    };
    let mut sup = 1;
    for _ in 0..n {
        sup *= 10;
    }
    for ans in 0..sup {
        if valid(ans) {
            println!("{}", ans);
            return;
        }
    }
    println!("-1");
}

fn main() {
    run();
}
