pub 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()
}

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

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::max;

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let sc: Vec<Vec<i32>> = read_vec2(m);

    let mut v = vec![-1; n];

    for i in 0..m {
        let s = sc[i][0] as usize - 1;
        let c = sc[i][1];

        if v[s] >= 0 && v[s] != c {
            println!("-1");
            return;
        }

        v[s] = c;
    }

    let mut ans = 0;
    for a in v {
        if ans == 0 && a == 0 {
            println!("-1");
            return;
        }
        ans *= 10;
        ans += max(a, 0);
    }
    println!("{}", ans);
}
