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

namespace AtCoderBeginnerContest157
{
	class Program
	{
		static void Main(string[] args)
		{
			var nm = ReadIntArray();
			var pairs = new List<(int X, int Y)>(nm[1]);
			for(var i = 0; i < nm[1]; i++)
			{
				var tmp = ReadIntArray();
				if ((nm[0] != 1 && tmp[1] == 0)
					|| (i != 0 && pairs.Any(x => x.X == tmp[0] && x.Y != tmp[1])))
				{
					Console.WriteLine("-1");
					return;
				}
				pairs.Add((tmp[0], tmp[1]));
			}

			switch (nm[0])
			{
				case 1:
				{
					if(nm[1] != 0 && pairs.Any(x => x.X == 1))
					{
						Console.WriteLine(pairs.Where(x => x.X == 1).ToArray()[0].Y);
						return;
					}
					else
					{
						Console.WriteLine(0);
						return;
					}
				}
				case 2:
				{
					var two = 1;
					var one = 0;
					if(nm[1] != 0 && pairs.Any(x => x.X == 1))
					{
						two = pairs.Where(x => x.X == 1).ToArray()[0].Y;
					}
					if(nm[1] != 0 && pairs.Any(x => x.X == 2))
					{
						one = pairs.Where(x => x.X == 2).ToArray()[0].Y;
					}
					Console.WriteLine(two * 10 + one);
					return;
				}
				case 3:
				{
					var three = 1;
					var two = 0;
					var one = 0;
					if (nm[1] != 0 && pairs.Any(x => x.X == 1))
					{
						three = pairs.Where(x => x.X == 1).ToArray()[0].Y;
					}
					if (nm[1] != 0 && pairs.Any(x => x.X == 2))
					{
						two = pairs.Where(x => x.X == 2).ToArray()[0].Y;
					}
					if (nm[1] != 0 && pairs.Any(x => x.X == 3))
					{
						one = pairs.Where(x => x.X == 3).ToArray()[0].Y;
					}
					Console.WriteLine(three * 100 + two * 10 + one);
					return;
				}
			}
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}
