use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    let mut s_vec = Vec::new();
    let mut c_vec = Vec::new();
    for _ in 0..m {
        let (s, c) = input_tuple();
        s_vec.push(s);
        c_vec.push(c);
    }

    for i in 0..s_vec.len() {
        for j in 0..s_vec.len() {
            if s_vec[i] == s_vec[j] && c_vec[i] != c_vec[j] {
                println!("-1");
                return;
            }
        }        
        if s_vec[i] == 1 && c_vec[i] == 0 {
            println!("-1");
            return;
        }
    }
    let mut num = vec![0; n as usize];
    for i in 0..s_vec.len() {
        num[(s_vec[i] - 1) as usize] = c_vec[i];
    }

    for n in num {
        print!("{}", n);
    }
    println!();
}
