import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		HashMap hs = new HashMap();
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next()) - 1;
		int m = Integer.parseInt(sc.next());
		int[][] s = new int[2][m];
		for(int i = 0 ; i < m ; i++){
			for(int j = 0 ; j < 2 ; j++){
				s[j][i] = Integer.parseInt(sc.next());
			}
			s[0][i]--;
			s[1][i] += 48;
		}
		sc.close();
		boolean ebishu = true;
		boolean yyyy = true;
		int k = 0;
		if(n == 0){
			yyyy = false;
			for(int i = 0 ; i < 10 ; i++){
				boolean ebi = true;
				for(int j = 0 ; j < m && ebi ; j++){
					if(s[1][j] - 48 != i) ebi = false;
				}
				if(ebi){
					ou.print(i);
					ebishu = false;
				}
			}
			if(ebishu){
				ou.print(-1);
				ebishu = false;
			}
		}
		for(k = (int)Math.pow(10 , n) ; yyyy && k < (int)Math.pow(10 , n + 1) && ebishu ; k++){
			String ss = String.valueOf(k);
			boolean ebi = true;
			for(int i = 0 ; i < m && ebi ; i++){
				if((int)ss.charAt(s[0][i]) != s[1][i]) ebi = false;
			}
			if(ebi){
				ou.print(k);
				ebishu = false;
				break;
			}
		}
		if(ebishu) ou.print(-1);
		ou.print("\n");
		ou.flush();
	}
}