use std::io::{stdin, BufRead};

fn main() {
    let ans = solve();
    println!("{}", ans.map(|n| n as i32).unwrap_or(-1));
}
fn solve() -> Option<u32> {
    let stdin = stdin();
    let mut stdinlock = stdin.lock();
    let mut nm = String::new();
    let _ = stdinlock.read_line(&mut nm).expect("read line!");
    let n: usize = nm
        .trim()
        .split_whitespace()
        .take(1)
        .map(|n| n.parse().expect("N"))
        .next()
        .expect("N");
    let mut digits: Vec<Option<u8>> = vec![None; n];
    for line in stdinlock.lines().map(|l| {
        (&l.expect("ln"))
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<u8>().expect("parse"))
            .collect::<Vec<_>>()
    }) {
        let d = digits.get_mut(line[0] as usize - 1).expect("Get error");
        if let Some(dig) = d {
            if dig != &line[1] {
                return None;
            }
        } else {
            *d = Some(line[1]);
        }
    }
    if digits[0].is_none() {
        digits[0] = Some(1);
    } else if digits[0] == Some(0) {
        return None;
    }
    let mut ans = 0;
    for &digit in &digits {
        ans *= 10;
        ans += digit.unwrap_or(0) as u32;
    }
    Some(ans)
}
