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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] tmpArr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int n = tmpArr[0];
			int m = tmpArr[1];

			int[] tmp = new int[n];
			int[] ans = new int[n];

			for (int i = 0; i < m; i++)
			{
				int[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

				if (arr[0] == 1 && arr[1] == 0)
				{
					Console.WriteLine(-1);
					return;

				}
				if (tmp[arr[0] - 1] != -1)
				{
					ans[arr[0] - 1] = arr[1];
					tmp[arr[0] - 1] = -1;
				}
				else
				{
					if (ans[arr[0] - 1] == arr[1]) continue;
					Console.WriteLine(-1);
					return;
				}
			}

			for (int i = 0; i < n; i++)
			{
				Console.Write(ans[i]);
			}

			return;
		}


	}


}
