macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, usize, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input! {
        n: u32,
        m: usize,
        sc: [(u32, i32); m],
    }
    if m == 0 {
        if n == 1 {
            println!("{}", 0);
            return;
        } else {
            println!("{}", 10i32.pow(n - 1));
            return;
        }
    }
    let mut sc = sc;
    sc.sort();
    sc.dedup();
    let m = sc.len();
    if (0..(m - 1)).any(|i| sc[i].0 == sc[i + 1].0 )
        || (n != 1 && sc[0].1 == 0) {
        println!("-1");
        return;
    }
    if n == 1 {
        println!("{}", sc[0].1);
        return;
    }
    let mut ans = 0;
    for (s , c) in sc { ans += c * 10i32.pow(n - s); }
    if ans < 10i32.pow(n - 1) { println!("{}", ans + 10i32.pow(n - 1)) }
    else { println!("{}", ans) }
}
