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

namespace GuessTheNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var numberDigits = int.Parse(input[0]);
            var numberInputs = int.Parse(input[1]);

            if (numberDigits > 3 || numberDigits < 1)
            {
                Console.WriteLine("-1");
                return;
            }

            if (numberInputs > 5)
            {
                Console.WriteLine("-1");
                return;
            }

            if (numberInputs == 0)
            {
                var output = 0;
                if (numberDigits == 3)
                {
                    output = 100;
                }
                Console.WriteLine(output);
                return;
            }

            List<KeyValuePair<int, int>> digitsRegister = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < numberInputs; i++)
            {
                var inputs = Console.ReadLine().Split(' ');

                if (int.Parse(inputs[0]) > numberDigits || int.Parse(inputs[1]) > 9)
                {
                    Console.WriteLine("-1");
                    return;
                }
                else if (int.Parse(inputs[0]) < 1 || int.Parse(inputs[1]) < 0)
                {
                    Console.WriteLine("-1");
                    return;
                }

                digitsRegister.Add(new KeyValuePair<int, int>(int.Parse(inputs[0]), int.Parse(inputs[1])));
            }

            int[] outputNumber = new int[numberDigits];
            for (int i = 0; i < numberDigits; i++)
            {
                if (digitsRegister.Any(x => x.Key == i + 1))
                {
                    var valueIndex = digitsRegister.FindLastIndex(x => x.Key == i + 1);
                    outputNumber[i] = digitsRegister[valueIndex].Value;
                }
            }

            string printOutput = "";
            if (outputNumber[0] == 0 && outputNumber[1] == 0 && numberDigits == 3)
            {
                Console.WriteLine("-1");
                return;
            }
            else
            {
                for (int i = 0; i < outputNumber.Count(); i++)
                {
                    printOutput += outputNumber[i];
                }
            }
            Console.WriteLine(printOutput);
        }
    }
}
