use std::vec::Vec;
use std::convert::TryInto;
fn main() {
    let first_in: Vec<u32> = read_as_vec().into_iter().map(|s| s.parse::<u32>().unwrap()).collect();
    let keta = first_in[0];
    let cnt = first_in[1];
    let mut sc_list: Vec<(u32, u32)> = Vec::new();
    for _ in 0..cnt {
        let mut sc = read_as_vec().into_iter().map(|s| s.parse::<u32>().unwrap());
        sc_list.push((sc.next().unwrap(), sc.next().unwrap()));
    }
    let mut start = String::with_capacity(keta.try_into().unwrap());
    if keta != 1 {
        start.push('1');
    }
    for _ in 1..keta {
        start.push('0');
    }
    let start = start.parse::<u32>().unwrap();
    let mut end = String::with_capacity(keta.try_into().unwrap());
    for _ in 0..keta {
        end.push('9');
    }
    let end = end.parse::<u32>().unwrap();

    let powed = 10u32.pow(keta - 1);
    let mut last: i64 = -1;
    'outer: for checking in start..=end {
        for (s, c) in &sc_list {
            if get_ketame(powed, checking, *s) != *c {
                continue 'outer;
            }
        }
        last = checking.try_into().unwrap();
        break;
    }
    println!("{}", last);
    // 123456
    //   |
    //
}
fn get_ketame(mut powed: u32, input: u32, need_keta: u32) -> u32{
    let mut result = 0;
    let mut checking = input;
    for _i in 0..need_keta {
        result = checking / powed;
        checking = checking % powed;
        powed = powed / 10;
    }
    result
}
fn read() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}
fn read_as_vec() -> std::vec::Vec<String> {
    read().split(' ').map(|s| s.to_string()).collect()
}
