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

class Program
{
	static void Main()
	{
		var nm = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var n = nm[0];
		var m = nm[1];

		var scs = new Dictionary<int, int>();
		for (var i = 0; i < m; ++i) {
			var sc = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
			if (scs.ContainsKey(sc[0])) {
				if (sc[1] != scs[sc[0]]) {
					Console.WriteLine(-1);
					return;
				}
			} else {
				scs.Add(sc[0], sc[1]);
			}
		}

		var sortedScs = scs.OrderBy(sc => sc.Key);

		var min = Math.Pow(10, n - 1);
		var max = Math.Pow(10, n) - 1;
		for (var i = min; i <= max; ++i) {
			var numText = i.ToString();
			var isRight = true;
			foreach (var sc in sortedScs) {
				if (numText.Length < sc.Key) {
					isRight = false;
					break;
				} else if (int.Parse(numText[sc.Key - 1].ToString()) != sc.Value) {
					isRight = false;
					break;
				}
			}

			if (isRight) {
				Console.WriteLine(i);
				return;
			}
		}

		Console.WriteLine(-1);

		//デバッグ実行での確認用。そのまま提出しても問題なし		
		Console.ReadKey();
	}
}
