#[allow(dead_code)]
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()
}

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

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

use std::collections::HashMap;

fn digit(n: u32) -> u32 {
    let mut n = n;
    let mut d = 0;
    while n != 0 {
        n /= 10;
        d += 1;
    }
    return d;
}

fn main() {
    let v: Vec<u32> = read_vec();
    let (n, m) = (v[0], v[1]);
    let mut map = HashMap::new();
    for _ in 0..m {
        let v2: Vec<u32> = read_vec();
        let (s, c) = (v2[0], v2[1]);
        if map.contains_key(&s) {
            if map.get(&s).unwrap() != &c {
                println!("{}", -1);
                return;
            }
        }
        map.insert(s, c);
    }
    let mut result = 0;
    if let Some(val) = map.get(&1) {
        result += val * 100;
    }
    if let Some(val) = map.get(&2) {
        result += val * 10;
    }
    if let Some(val) = map.get(&3) {
        result += val;
    }

    if digit(result) == n {
        println!("{}", result);
    } else {
        println!("{}", -1);
    }
}
