use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut v: [usize; 3] = [10;3];
    let mut m:usize = read!();
    for i in 0..m {
        let s:usize = read!();
        let c:usize = read!();
        if v[s-1] == c ||v[s-1] == 10{
            v[s-1] = c;
        }
        else {
            println!("-1");
            exit(0);
        }
    }
    if v[0]==0 {
        println!("-1");
        exit(0);
    }
    if v[0]==10 {
        v[0]=1;
    }
    println!("{}",(v[0]%10)*100+(v[1]%10)*10+v[2]%10);
}