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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut ans = vec![0; n];

    for _ in 0..m {
        let s: usize = read();
        let c: i32 = read();
        if ans[s - 1] == c || ans[s - 1] == 0 {
            ans[s - 1] = c;
        } else {
            ans.clear();
            break;
        }
        if s == 1 && c == 0 {
            ans.clear();
        }
    }
    if ans.is_empty() {
        println!("-1");
    } else {
        if ans[0] == 0  && ans.len() > 1 {
            ans[0] = 1;
        }
        for i in ans {
            print!("{}", i);
        }
    }
    println!("");
}
