use std::io::{BufRead, BufReader};
use std::collections::HashMap;

fn main(){
    let lines = read::<String>();
    let nm:Vec<i32> = lines[0].split(' ').map(|i| i.parse().unwrap()).collect();
    let n = nm[0];

    let mut hash: HashMap<i32,i32> = HashMap::new();
    let mut can_solve = true;

    lines
        .into_iter()
        .skip(1)
        .map(|l| {
            let sc: Vec<i32> = l.split(' ').map(|i| i.parse().unwrap()).collect();
            let s: i32 = sc[0];
            let c: i32 = sc[1];
            let x = hash.entry(s).or_insert(c);
            if *x != c {
                can_solve = false;
            } else if  n != 1 && s == 1 && *x == 0 {
                can_solve = false;
            };
        }).count();

    let mut ans: i32 = 0;
    if !can_solve {
        ans = -1;
    } else {
        let mut base: i32 = 1;
        for i in 1..n+1 {
            let k: u32 = (n - i) as u32;
            ans +=  *hash.entry(i).or_insert(base) * 10i32.pow(k);
            base = 0;
        }
    }

    println!("{}", ans);
}

fn read<T>() -> Vec<T>
where
  T: std::str::FromStr,
  T::Err: std::fmt::Debug,
{
    let lines: Vec<T> =
        BufReader::new(std::io::stdin())
        .lines()
        .map(|l| l.unwrap().parse::<T>().unwrap())
        .collect();
    lines
}
