using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
			// 整数配列の入力
			var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

			var N = inputLongArray[0];
			var M = inputLongArray[1];

			Dictionary<int,int> sList = new Dictionary<int, int>();

			for (int i = 0; i < M; ++i) {
				var input = Console.ReadLine().Split(' ').Select(j => int.Parse(j)).ToArray();

				if (sList.ContainsKey(input[0])) {
					if(sList[input[0]] != input[1]) {
						Console.WriteLine(-1);
						return;
					}
				} else {
					sList.Add(input[0],input[1]);
				}
			}

			var distinctList = sList.Distinct();
			//if(distinctList.Where(x => x.Value == distinctList.First().Value).Count() != distinctList.Count()) {
			//	Console.WriteLine(-1);
			//}

			string result = "";
			for(int j = 0; j<N; ++j) {
				var target = distinctList.Where(x => x.Key == j + 1).FirstOrDefault();
				if(target.Key == 0) {
					result += "0";
				} else {
					result += target.Value.ToString();
				}
			}

			if(int.Parse(result).ToString() != result) {
				Console.WriteLine(-1);
				return;

			}

			Console.WriteLine(result);
		}

	}
}