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

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            var S = new int[NM[1]];
            var C = new int[NM[1]];
            for (int i = 0; i < NM[1]; i++)
            {
                var line = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                S[i] = line[0];
                C[i] = line[1];
            }

            var val = 1;
            for (int i = 0; i < NM[0]; i++)
            {
                val *= 10;
            }

            var min = int.MaxValue;
            for (int i = 0; i < val; i++)
            {
                var len = i.ToString();

                var isCandidate = true;
                for (int k = 0; k < S.Length; k++)
                {
                    if (len.Length < S[k])
                    {
                        isCandidate = false;
                        break;
                    }
                    else if (len.Substring(len.Length - S[k], 1) != C[k].ToString())
                    {
                        isCandidate = false;
                        break;
                    }
                }
                if (isCandidate) min = Math.Min(i, min);
            }

            Console.WriteLine(min == int.MaxValue ? -1 : min);

        }
    }
}
