use std::io::stdin;

fn main() {
    let mut nm = input_i32_Vec();
    let (mut n,mut m) = (&nm[0], &nm[1]);
    let mut array:Vec<i32> = [-1; 6].to_vec();
    let mut result:i32 = 0;
    for i in 0..*m {
        let mut sc = input_i32_Vec();
        if array[sc[0] as usize] < 0 {
            array[sc[0] as usize] = sc[1];
            result += sc[1]*(10_i32.pow((m-sc[0]) as u32))
        } else {
            if array[sc[0] as usize] != sc[1] {
                result = -1;
                break;
            } else {
                continue;
            };
        };
    };
    if result <= 0 {
        println!("-1");
    } else {
        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
}