using System;
using System.Linq;

class C
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int n = h[0], m = h[1];
		var scs = new int[m].Select(_ => Read()).ToArray();

		var r = Enumerable.Range(0, 1000)
			.Select(i => i.ToString())
			.First(s => s.Length == n && scs.All(sc => s[sc[0] - 1] - '0' == sc[1]));
		Console.WriteLine(r ?? "-1");
	}
}
