use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut map: HashMap<usize, usize> = HashMap::new();
    for _i in 0..m {
        let s: usize = iterator.next().unwrap().parse().unwrap();
        let c: usize = iterator.next().unwrap().parse().unwrap();
        if n != 0 && s == 1 && c == 0 {
            return "-1".to_string();
        }

        let old = map.insert(s, c);
        if let Some(x) = old {
            if x != c {
                return "-1".to_string();
            }
        }

    }

    let mut ans: usize = 0;
    for i in 1..(n + 1) {
        ans *= 10;

        let value = map.get(&i);
        ans += match value {
            Some(&x) => x,
            _ => if i == 1 { 1 } else { 0 }
        };
    }

    return ans.to_string();
}
