#[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 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;
            }
        } else {
            map.insert(s, c);
        }
    }

    if n == 3 {
        let d3 = map.get(&1);
        let d2 = map.get(&2);
        let d1 = map.get(&3);
        for i in 100..1000 {
            if let Some(d1) = d1 {
                if i % 10 != *d1 {
                    continue;
                }
            }
            if let Some(d2) = d2 {
                if (i % 100) / 10 != *d2 {
                    continue;
                }
            }
            if let Some(d3) = d3 {
                if i / 100 != *d3 {
                    continue;
                }
            }
            println!("{}", i);
            return;
        }
    }

    if n == 2 {
        if map.contains_key(&3) {
            println!("{}", -1);
            return;
        }
        for i in 10..100 {
            if let Some(d1) = map.get(&2) {
                if i % 10 != *d1 {
                    continue;
                }
            }
            if let Some(d2) = map.get(&1) {
                if i / 10 != *d2 {
                    continue;
                }
            }
            println!("{}", i);
            return;
        }
    }

    if n == 1 {
        if map.contains_key(&3) || map.contains_key(&2) {
            println!("{}", -1);
            return;
        }
        for i in 0..10 {
            if let Some(d1) = map.get(&1) {
                if i == *d1 {
                    println!("{}", i);
                    return;
                }
            }
        }
    }

    println!("{}", -1);
}
