use whiteread::parse_line;

fn main() {
    let (n, m): (usize, usize) = parse_line().unwrap();
    let mut num: Vec<Option<u8>> = vec![None; n];

    for _ in 0..m {
        let (si, ci): (usize, u8) = parse_line().unwrap();
        if si == 1 && ci == 0 {
            println!("-1");
            return;
        }
        if let Some(c) = num[si - 1] {
            if ci != c {
                println!("-1");
                return;
            }
        } else {
            num[si - 1] = Some(ci);
        }
    }

    let mut num = num
        .iter()
        .map(|x| match x {
            Some(c) => *c,
            None => 0,
        })
        .collect::<Vec<_>>();
    if num[0] == 0 {
        num[0] = 1;
    }

    println!("{}", num.iter().fold(0_u32, |x, &y| x * 10 + y as u32));
}
