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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var n = p[0];
		var m = p[1];
		var k = new int[n];
		for(int i = 0; i < n; i++)
			k[i] = -1;
		
		for(int i = 0; i < m; i++)
		{
			p = Input().ToInt();
			if(k[p[0]-1] !=-1 && p[1] != k[p[0]-1])
			{
				Console.WriteLine(-1);
				return;
			}
			k[p[0]-1] = p[1];
		}
		bool start = false;
		for(int i = 0; i < n; i++)
		{
			if(k[i]>0)start=true;
			if(!start && k[i]<=0) continue;
			
			Console.Write(k[i]==-1?0:k[i]);
		}
		if(!start)
		{
			Console.WriteLine(-1);
			return;
		}
		Console.WriteLine();
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}
