use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeMap;
use std::cmp::min;

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

fn main(){
    let n: usize = read();
    let m: usize = read();
    let mut a: Vec<u8> = (0..n).map(|_| 10).collect();
    for _ in 0..m {
        let s: usize = read::<usize>() - 1;
        let c: u8 = read();
        if a[s] != c && a[s] != 10 {
            println!("-1");
            return;
        }
        a[s] = c;
    }
    if a[0] == 0 {
        println!("-1");
        return;
    } else if a[0] == 10 {
        a[0] = 1;
    }
    //a.reverse();

    for b in &a {
        print!("{}", if *b == 10 { 0 } else { *b });
    }
    println!("");
}
