use std::io::{self, BufRead};

fn main() {
    let mut buf = String::new();
    let mut r = io::BufReader::new(io::stdin());

    let (n, _m): (usize, usize) = {
        r.read_line(&mut buf);
        let mut i = buf.split(" ").map(|x| x.trim().parse().unwrap());
        (i.next().unwrap(), i.next().unwrap())
    };

    let mut digits: Vec<i32> = vec![-1; n];

    // false conditions
    //  * leading zero
    //  * same position different number

    let mut ok = true;

    for l in r.lines() {
        let l = l.unwrap();
        let mut iter = l.split(" ").map(|x| x.trim().parse::<i32>().unwrap());
        let s = iter.next().unwrap() as usize - 1;
        let c = iter.next().unwrap();
        if digits[s] >= 0 {
            ok = false;
        }
        digits[s] = c;
    }

    ok = digits[0] > 0;

    if ok {
        println!(
            "{}",
            digits
                .iter()
                .rev()
                .enumerate()
                .fold(0, |acm, (i, &n)| acm + (if n <= 0 { 0 } else { n }) * 10_i32.pow(i as u32))
        );
    } else {
        println!("-1");
    }
}