fn main() {
    let (n, m) = read_tuple();
    let mut num: Vec<Option<u8>> = vec![None; n];
    let mut ans = true;

    for _ in 0..m {
        let (s, c) = read_tuple::<u8>();
        num[(s-1) as usize] = match num[(s-1) as usize] {
            Some(v) => {
                if v == c {
                    Some(c)
                } else {
                    ans = false;
                    None
                }
            },
            None => {
                Some(c)
            }
        };
    }

    // println!("{:?}", num);
    // println!("{:?}", ans);
    if ans && num[0] != Some(0) {
        if num[0].is_none() {
            num[0] = Some(1);
        }
        let mut x = 0;
        for (i, s) in num.iter().enumerate() {
            x += 10_i32.pow((n - i - 1) as u32) * s.or(Some(0)).unwrap() as i32;
        }
        println!("{:?}", x);
    } else {
        println!("-1");
    }


}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}

