use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        sc: [(usize, usize); m],
    }
    let mut ans = 0;
    for (s, c) in sc {
        if (s==1) && c==0 { println!("-1"); return; }
        let dig = 10_usize.pow((n-s) as u32);
        let digit_num = (ans/dig) % 10;
        if digit_num == 0 { ans += dig*c }
        else if digit_num != c { println!("-1"); return; }
    }
    let top_digit = 10_usize.pow((n-1) as u32);
    if ans < top_digit { ans += top_digit; }
    println!("{}", ans);
}
