using System;
using System.Linq;
using System.Xml;

namespace C {
    class Program {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var digit = input[0];
            var hints = input[1];

            var isOverlapped = false;
            var isRuleViolated = false;

            var answer = new int?[digit];

            int aDigit;
            int aNumber;
            foreach (var _ in Enumerable.Range(0, hints))
            {
                input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                aDigit = input[0] - 1;
                aNumber = input[1];

                if (answer[aDigit] != null && answer[aDigit] != aNumber) isOverlapped = true;

                if (digit != 1 && aNumber == 0 && aDigit == 0) isRuleViolated = true;

                answer[aDigit] = aNumber;
            }

            if (isOverlapped || isRuleViolated)
            {
                Console.WriteLine(-1);
                return;
            }

            var a = answer.Select(x => x ?? 0);
            var number = int.Parse(string.Join(null, a));
            var output = 0;
            while (output != number)
                output++;
            Console.WriteLine(output);
        }
    }
}
