#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut d = vec![];
    for i in 0..m {
        let v = read_vec::<usize>();
        d.push((v[0] - 1, v[1]));
    }
    let mut nums = vec![10; n]; // 10 is unset
    for (s, c) in d {
        if s == 0 && c == 0 && n != 1 {
            println!("-1");
            return;
        }
        if nums[s] != 10 && nums[s] != c {
            println!("-1");
            return;
        }
        nums[s] = c;
    }
    for num in nums {
        if num == 10 {
            print!("{}", 0);
        } else {
            print!("{}", num);
        }
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
