use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let nm:Vec<_> = st.trim().split(" ").map(|x| x.parse::<i32>().unwrap()).collect();
    let mut array:Vec<i32> = [-1; 10].to_vec();
    let mut result:i32 = 0;
    for _ in 0..*&nm[1] {
        let sc = input_i32_Vec();
        if array[sc[0] as usize] < 0 {
            if sc[0]==nm[1] && sc[1]==0 {
                result = -1;
                break;
            };
            array[sc[0] as usize] = sc[1];
            result += sc[1]*(10_i32.pow((&nm[1]-sc[0]) as u32))
        } else {
            if array[sc[0] as usize] == sc[1] {
                continue;
            } else {
                result = -1;
                break;
            };
        };
    };
    if result==0 && nm[0]==1{
        println!("0");
    } else if result < 0 {
        println!("-1");
    } else {
        if result < 10_i32.pow((&nm[1]-1) as u32) {
            result += 10_i32.pow((&nm[1]-1) as u32);
        };
        println!("{}", result);
    }
}

fn input_i64() -> i64 {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    st.trim().parse::<i64>().unwrap()
}

fn input_i64_Vec() -> Vec<i64> {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let mut ret:Vec<_> = st.split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect();
    ret
}

fn input_i32_Vec() -> Vec<i32> {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let mut ret:Vec<_> = st.split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect();
    ret
}