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

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
#if TextInput
			using(var reader = new StreamReader(Debug.SampleTextPath)) 
			{
				Console.SetIn(reader);
#endif

				var intArray = IO.ReadIntArray();
				var numbers = Enumerable.Repeat(-1 , intArray[0]).ToArray();
				for(var iIndex = 0 ; iIndex < intArray[1] ; ++ iIndex)
				{
					var checkIntArray = IO.ReadIntArray();
					var index = checkIntArray[0] - 1;
					if(numbers[index] == -1)
					{
						numbers[index] = checkIntArray[1];
					}
					else if(numbers[index] != checkIntArray[1])
					{
						numbers = null;
						break;
					}
				}

				var answer = -1;
				if(numbers != null && numbers[0] != 0)
				{
					for(var iIndex = 0 ; iIndex < intArray[0] ; ++ iIndex)
					{
						if(numbers[iIndex] == -1) { numbers[iIndex] = 0; }
					}
					if(intArray[0] > 1 && numbers[0] == 0) { numbers[0] = 1; }
					answer = int.Parse(string.Join("" , numbers));
				}
				IO.Write(answer);
#if TextInput
			}
#endif
		}
	}

	public static class IO
	{
		public static string   Read()								 { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')		 { return Read().Split(iSplitter); }
		public static int	   ReadInt()							 { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()							 { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static double   ReadDouble()							 { return double.Parse(Read()); }
		public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()						 { return Read().ToCharArray(); }

		public static void Write(string iValue)									   { Console.WriteLine(iValue); }
		public static void Write(int iValue)									   { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue , string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord , iValue)); }
		public static void Write(long iValue)									   { Console.WriteLine(iValue); }
		public static void Write(double iValue)									   { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)								   { Console.WriteLine(iValue); }
		public static void Write(bool iValue)									   { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}
		public static long CombinationNum(int iLeftNumber , int iRightNumber)
		{
			if(iRightNumber == 0) { return 1; }
			if(iLeftNumber == 0)  { return 0; }
			return iLeftNumber * CombinationNum(iLeftNumber - 1 , iRightNumber - 1) / iRightNumber;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}
