use std::collections::HashMap;
use std::io;

fn main() {
	let mut flag = true;
	
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let n: i32 = match iter.next().unwrap().parse(){
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	let m: i32 = match iter.next().unwrap().parse(){
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	
	let mut map: HashMap<i32, i32> = HashMap::new();
	if m != 0 && m <= 3 {
		for num in 0..m {
			let mut buf = String::new();
			io::stdin().read_line(&mut buf).expect("");
			let mut iter = buf.split_whitespace();
			let s = match iter.next().unwrap().parse(){
				Ok(n) => n,
				Err(_) => panic!(""),
			};
			let c = match iter.next().unwrap().parse(){
				Ok(n) => n,
				Err(_) => panic!(""),
			};
			
			match map.insert(s, c) {
				Some(n) => if n != c{
					println!("-1");
					flag = false;
					break;
				},
				None => (),
			}
			
		}
		if flag {
			let mut v: Vec<i32> = Vec::new();
			if n == 1 {
				
				println!("{}", map.get(&1).unwrap() );
				
			}else if n != 1 {
				match map.get(&1) {
					Some(&0) => {
						println!("-1");
					},
					
					Some(_) => {
						for number in 0..n {
							match map.get(&(number+1)){
								Some(n) => v.push(*n),
								None => v.push(0),
							}
						}
				
						for n in v {
							print!("{}", n);
						}
						print!("\n");
					},
					
					None => {
						v.push(1);
						for number in 1..n {
							match map.get(&(number+1)){
								Some(n) => v.push(*n),
								None => v.push(0),
							}
						}				
						for n in v {
							print!("{}", n);
						}
						print!("\n");
					}
				}
			}else{
				println!("-1");
			}
		}
		
	}else{
		println!("-1");
	} 
	
}