use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();

    let v: Vec<(usize, usize)> = (0..m).map(|_| (read(), read())).collect();
    let mut ans: Vec<i32> = vec![-1; n];
    for (s, c) in v {
        if ans[n-s] == -1 || ans[n-s] == c as i32{
            ans[n-s] = c as i32;
        } else {
            println!("-1");
            return;
        }
    }

    let mut a = 0;
    let mut ten = 1;
    for (i, &k) in ans.iter().enumerate() {
        if i == n-1 && k == 0 {
            println!("-1");
            return;
        }
        if k==-1{
            a += 0;
        } else {
            a += ten*k
        }
        ten *= 10;
    }

    if a < 10_i32.pow((n-1) as u32) {
        a += 10_i32.pow((n-1) as u32);
    }

    println!("{}", a);
}
