using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		//文字列を読み込む
		int[] L1 = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int N = L1[0];
		int M = L1[1];
		
		//各桁の数値を格納する配列
		int[] digits = new int[N];
		
		//答えがあるか判定する変数
		bool answerExists = true;
		
		for(int i=0; i<M; i++){
				int[] L2 = Console.ReadLine().Split(' ').Select(j => int.Parse(j)).ToArray();
				int si = L2[0] - 1;
				int ci = L2[1];
				
				if(digits[si] == 0){
						digits[si] = ci;
				}
				else if(digits[si] != ci){
						answerExists = false;
						break;
				}
				
				if(N !=1 && si == 0 && ci == 0){
						answerExists = false;
						break;
				}
		}
		
		if(digits[0] == 0){
				digits[0] = 1;
		}
		
        if(answerExists)
		{
			string answer = "";
			for(int i=0; i<N; i++){
					answer += digits[i].ToString();
			}
			Console.WriteLine(answer);
		}else{
			Console.WriteLine("-1");
		}
	}
}