using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;

namespace Atcoder
{
	class Program
	{
		/*
			string s = Console.ReadLine();
			string[] ST = Console.ReadLine().Split(' ').ToArray();
			string S = strArray[0];
			string T = strArray[1];

			int[] HWN = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int H = intArray[0];
			int W = intArray[1];
			int N = int.Parse(Console.ReadLine());

			List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToList());
			
			double[] R = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();

			Boolean ok = false;
			
			List<int> dp = Enumerable.Repeat(値, 個数).ToList();
			
			Console.WriteLine(ans);
			Console.WriteLine("Yes");
			Console.WriteLine("No");
			Console.ReadKey();
			Console.WriteLine(cnt);

			for(int i= 0; i < N; i++)
			(char)((a + N - 'a') % 26 + 'a') + "";
		*/

		static void Main(string[] args)
		{
			int[] NM = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int N = NM[0];
			int M = NM[1];

			int[,] sc = new int[M, 2];
			for (int i = 0; i < M; i++)
			{
				int[] SCM = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
				sc[i, 0] = SCM[0];
				sc[i, 1] = SCM[1];
			}

			List<int> dp = Enumerable.Repeat(0, N).ToList();
			List<bool> flg = Enumerable.Repeat(false, N).ToList();

			for (int i = 0; i < M; i++)
			{
				if (!flg[sc[i, 0] - 1])
				{
					dp[sc[i, 0] - 1] = sc[i, 1];
					flg[sc[i, 0] - 1] = true;
				}
				else if (dp[sc[i, 0] - 1] == sc[i, 1])
				{
					continue;
				}
				else
				{
					Console.WriteLine(-1);
					return;
				}
			}
			if (dp[0] == 0 && dp.Count() != 1)
			{
                if (flg[0])
                {
					Console.WriteLine(-1);
					return;
				}
				dp[0] = 1;
			}
			
			string ans = "";
			for (int i = 0; i < N; i++)
			{
				ans += dp[i];
			}
			Console.WriteLine(ans);
		}

		class Item : IComparable
		{
			public string A;
			public int B;
			public Item(string a, int b)
			{
				this.A = a;
				this.B = b;
			}
			public int CompareTo(object obj)
			{
				return B - ((Item)obj).B;
			}
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			//char[] val1 = word1.ToCharArray();
			//char[] val2 = word2.ToCharArray();
			//Array.Sort(val1);
			//Array.Sort(val2);
			//word1 = new string(val1);
			//word2 = new string(val2);

			//return word1 == word2;
			return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}

		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 28336