import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		
		int m = stdIn.nextInt();
		
		
		
		Map <Integer, Integer> map = new HashMap<>();
		
		for(int i = 0; i < m; i++) {
			int b = stdIn.nextInt();
			int e = stdIn.nextInt();
			if(!map.containsKey(b)) {
				map.put(b,e);
			}
			
			if(map.get(b) != e || b == 1 && e == 0 || n==1 && e == 0) {
				System.out.println("-1");
				System.exit(0);
			}
			
		}
		if(m==0) {
			System.out.print("1");
			System.exit(0);
		}
		
		int index = 1;
		
		if(n==3) {
			for(Integer key: map.keySet()) {
				if(index == key) {
					System.out.print(map.get(index));
					index++;
				}else {
					System.out.print("0");
					index++;
					System.out.print(map.get(index));
				}
				if(!map.containsKey(3)) {
					System.out.print("0");
				}
			}
		}else if(n == 2) {
			for(Integer key: map.keySet()) {
				
				if(index == key) {
					System.out.print(map.get(index));
					index++;
				}
				if(!map.containsKey(2)) {
					System.out.print("0");
				}
			}
				
			}else {
				System.out.print(map.get(index));
			}
			
			
			
			
		
		
		
		
		
		
		
		
		
		
		
		
	}

}
