use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let (n, m) = parse!(it, 2);
    let mut ret = vec![None; n];
    for _ in 0..m {
        let (s, t): (usize, usize) = parse!(it, 2);
        match ret[s - 1] {
            None => ret[s - 1] = Some(t),
            Some(r) => {
                if t != r {
                    println!("{}", -1);
                    return;
                }
            }
        };
    }
    if n > 1 && ret[0] == Some(0) {
        println!("{}", -1);
        return;
    }
    if ret[0] == None {
        ret[0] = Some(1);
    }
    println!(
        "{}",
        ret.into_iter()
            .map(|x| match x {
                None => 0,
                Some(t) => t,
            })
            .map(|x| std::char::from_digit(x as u32, 10).unwrap())
            .collect::<String>()
    );
}
