macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn adder (i: usize, j: usize) -> isize{
    let mut pow: usize = 1;
    for k in 1..i {
        pow *= 10;
    }
    (pow * j) as isize
}

fn main(){
    input!{
        n: usize,
        m: usize,
        s: [(usize, usize); m]
    }
    let mut new = s;
    new.sort();
//    new.sort_by(|&(x, y), &(a, b)| x.cmp(&a) && y.cmp(&b));
    let mut a: usize = 0;
    let mut b: usize = 0;
    let mut result: isize = 0;
    for (i, j) in new {
        if i == 1 && j == 0 && n < 2 {result = -1; break}
        if i == a && j != b {result = -1; break;}
        else if i == a && j == b {}
        else {
            result += adder(n-i+1, j);
        }
        a = i;
        b = j;
    }
    print!("{}", if n < 2 {result} else if result == -1 {-1} else if adder(n, 1) <= result && result < adder(n+1, 1){result} else {result + adder(n, 1)})
}
