use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, m: usize, sc: [[usize; 2]; m]};

    let ten: i64 = 10;

    if m > 0 {
        if n != 1 {
            f(ten.pow((n - 1) as u32), ten.pow(n as u32), sc, n);
        } else {
            f(0, 10, sc, n);
        }
    } else {
        if n == 1 {
            println!("0");
        }
    }
}

fn f(br: i64, ur: i64, sc: Vec<Vec<usize>>, n: usize) {
    let mut is_valid = true;
    for num in br..ur {
        let mut judge = true;
        for sc_i in sc.iter() {
            let s = sc_i[0];
            let c = sc_i[1];

            let ns = num.to_string();

            if s == 1 && c == 0 && n != 1 {
                judge = false;
                break;
            }

            if &ns[s - 1..s] != c.to_string() {
                judge = false;
            }
        }

        if judge {
            println!("{}", num);
            is_valid = false;
            break;
        }
    }

    if is_valid {
        println!("-1");
    }
}
