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

namespace CSharpSample01
{


	class Program
	{
		static void Main(string[] args)
		{
			var inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var N = inputNum[0];
			var M = inputNum[1];

			var dicInput = new Dictionary<int, List<int>>();

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

				if(dicInput.ContainsKey(inputRule[0]))
				{
					dicInput[inputRule[0]].Add(inputRule[1]);
				}
				else
				{
					dicInput[inputRule[0]] = new List<int> { inputRule[1] };
				}
			}

			var flag = true;

			if(dicInput.ContainsKey(1))
			{
				if(dicInput[1].Any(x => x == 0))
				{
					flag = false;
				}
			}

			if(flag)
			{
				for (int i = 1; i <= N; i++)
				{
					if(dicInput.ContainsKey(i))
					{
						if (dicInput[i].Distinct().Count() > 1)
						{
							flag = false;
							break;
						}
					}
				}
			}

			var answer = "";
			// 出力
			if(flag)
			{
				if(dicInput.ContainsKey(1))
				{
					answer += dicInput[1].First();
				}
				else
				{
					answer += "1";
				}

				if(N > 1)
				{
					if (dicInput.ContainsKey(2))
					{
						answer += dicInput[2].First();
					}
					else
					{
						answer += "0";
					}
				}

				if (N > 2)
				{
					if (dicInput.ContainsKey(3))
					{
						answer += dicInput[3].First();
					}
					else
					{
						answer += "0";
					}
				}
				Console.WriteLine(answer);
			}
			else
			{
				if(N == 1)
				{
					if (dicInput.ContainsKey(1))
					{
						if (dicInput[1].Count == 1 && dicInput[1].First() == 0)
						{
							Console.WriteLine(0);
						}
						else
						{
							Console.WriteLine(-1);
						}
					}
					else
					{
						Console.WriteLine(-1);
					}
				}
				else
				{
					Console.WriteLine(-1);
				}

			}

		}
	}
}