use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        mut instructions: [(usize, usize); m],
    }
    
    let instructions: Vec<(usize, usize)> = instructions.iter().map(|inst| (inst.0-1, inst.1)).collect();
    let mut integer: Vec<Option<usize>> = vec![None; n];

    for instruction in &instructions {
        if n != 1 && instruction.0 == 0 && instruction.1 == 0 {
            println!("{}", -1);
            return;
        } 
        if let Some(num) = integer[instruction.0] {
            if num != instruction.1 {
                println!("{}", -1);
                return;
            }
        } else {
            integer[instruction.0] = Some(instruction.1)
        }
    }

    for i in &integer {
        match i {
            Some(num) => print!("{}", num),
            None => print!("{}", 0)
        }
    }

    println!();
}