fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<_> = (0..m).map(|_| {
		(s.next().unwrap().parse::<usize>().unwrap(), s.next().unwrap().parse::<usize>().unwrap())
	}).collect();
	let range = match n {
		1 => 0..10,
		2 => 10..100,
		3 => 100..1000,
		_ => panic!(),
	};
	'a: for i in range {
		let mut j = i;
		let mut d = vec![];
		for _ in 0..n {
			d.push(j % 10);
			j /= 10;
		}
		for (s, c) in a.iter() {
			if d[n - s] != *c {
				continue 'a;
			}
		}
		println!("{}", i);
		return;
	}
	println!("-1");
}
