use std::io::stdin;

fn main(){
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let nm:Vec<i32> = st.split_whitespace().map(|x| x.parse().unwrap()).collect();

    let mut result:i32 = 0;

    let mut array:Vec<i32> = [-1; 4].to_vec();

    let mut s:Vec<i32> = Vec::with_capacity(nm[1] as usize);
    let mut t:Vec<i32> = Vec::with_capacity(nm[1] as usize);
    for _ in 0..*&nm[1] {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        let st:Vec<i32> = st.split_whitespace().map(|x| x.parse().unwrap()).collect();   
        s.push(st[0]);
        t.push(st[1]);    
    };

    for i in 0..*&nm[1] {
        let i = i as usize;
        if s[i]==1 && t[i]==0 {
            result = -1;
            break;
        } else if array[s[i] as usize] < 0 {
            array[s[i] as usize] = t[i];
            result += t[i]*(10_i32.pow((nm[1]-s[i]) as u32));
        } else {
            if array[s[i] as usize] == t[i] {
                continue;
            } else {
                result = -1;
                break;
            };
        };
    };

    if result < 0 {
        println!("-1");
    } else if nm[0]==1 {
        println!("{}", result);
    } else if nm[1] == 0{
        println!("{}", 10_i32.pow((nm[0]-1) as u32))
    } else {
        if result < 10_i32.pow((nm[0]-1) as u32) {
            result += 10_i32.pow((nm[0]-1) as u32);
        };
        println!("{}", result);
    };
}