fn main() {
    let n: usize = read();
    let mut d = vec![0 as u8; n];
    for _ in 0..read::<usize>() {
        let si = read::<usize>();
        let ci = read::<u8>();
        let old = d.get_mut(si - 1).unwrap();
        if *old == 0 {
            *old = ci;
        } else if *old > ci {
            *old = ci;
        }
    }
    if *d.get(0).unwrap() == 0 {
        println!("-1");
        return;
    }
    let s = String::from_utf8(d.into_iter().map(|x| x + b'0').collect()).unwrap();
    println!("{}", s);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed 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")
}
