use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}
fn get_vec_by_lines<T : FromStr>(n : usize) -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for _i in 0..n {
        let x : T = get_one();
        v.push(x);
    }
    return v;
}


fn main() {
    let nm : Vec<usize> = get_vec();
    let n : usize = nm[0];
    let m : usize = nm[1];
    let mut v = vec!(0_u32;n);
    let mut exists = vec!(false;n);
    let mut ans = true;
    for i in 0..m {
        let sc : Vec<u32> = get_vec();
        let s = sc[0] as usize;
        let c = sc[1];
        if exists[s-1] && c != v[s-1] {
            ans = false;
            break;
        }
        v[s-1] = c;
        exists[s-1] = true;
    }
    let mut s = String::new();
    for i in 0..n {
        s = format!("{}{}", s, v[i].to_string());
    }
    if ans && v[v.len()-1] != 0 {
        println!("{}", s);
    }
    else {
        println!("{}", -1);
    }
}
