#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        s: [(usize, usize); m]
    }
    let mut c: Vec<usize> = vec![10; n + 1];
    for i in s.iter() {
        if c[i.0] == 10 || c[i.0] == i.1 {
            c[i.0] = i.1;
        } else {
            println!("-1");
            return;
        }
    }
    if n > 1 && c[n] == 0 || c[n] == 10 {
        println!("-1");
        return;
    }
    let mut tmp = 0;
    for j in 0..n + 1 {
        if c[j] == 10 {
            continue;
        }
        tmp += c[j] * 10usize.pow((n - j) as u32);
    }
    println!("{:?}", tmp);
}
