fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        sc: [(usize,i8);m],
    }
    let inf = std::i8::MAX;
    let mut a=vec![inf;n];
    for (s,c) in sc {
        if s<1 || n<s {
            a[0]=-1;
            break;
        }
        if a[s-1]>c {
            a[s-1]=c;
        }
    }
    if a[0]==inf || a[0]==0 {
        println!("-1");
        return;
    }
    for a in a.iter_mut() {
        if *a==inf {
            *a=0;
        }
    }
    println!("{}",itertools::join(a, ""));
}