use std::char;
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let mut s: Vec<i32> = vec![0; m];
    let mut c: Vec<u32> = vec![0; m];
    for i in 0..m {
        s[i] = iter.next().unwrap().parse().unwrap();
        c[i] = iter.next().unwrap().parse().unwrap();
    }
    let mut ans :Vec<char> = vec![' '; n];

    for i in 0..m {
        let c = char::from_u32(c[i] + ('0' as u32)).unwrap();
        let index = (s[i]-1) as usize;
        if ans[index] != ' ' && ans[index] != c {
            println!("{}", -1);
            return;
        }
        ans[index] = c;
    }
    for i in 0..n {
        if ans[i] == ' ' { ans[i] = '0' }
    }
    if n > 1 && ans[0] == '0' {
        println!("{}", -1);
    }else {
        println!("{}", &ans.iter().collect::<String>());
    }
}
