use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let m = nm[1];
    let mut digits = vec![HashSet::new(); n];

    if m == 0 {
        if n == 1 {
            println!("0");
            return;
        }
        print!("1");
        for _ in 1..n {
            print!("0");
        }
        println!("");
        return;
    }

    for _ in 0..m {
        let sc = read_vec::<usize>();
        let s = sc[0];
        let c = sc[1];
        digits[s-1].insert(c);
    }
    let digits = digits.iter().collect::<Vec<_>>();

    if digits[0].contains(&0) {
        println!("-1");
        return;
    }
    for i in 0..n {
        if digits[i].len() > 1 {
            println!("-1");
            return;
        }
    }

    if digits.iter().filter(|x| x.is_empty() == false).count() == 0 {
        println!("0");
        return;
    }

    for (i, d) in digits.iter().enumerate() {
        match d.iter().collect::<Vec<_>>().first() {
            Some(num) => { print!("{}", num); },
            None => { if i == 0 { print!("1"); } else {print!("0"); } },
        }
    }
    println!("");
}