using System;
using System.Collections.Generic;

namespace CsAtCoderSubmitExam
{
    class BeginnerContest157
    {
        // C - Guess The Number
        class SC
        {
            public int S;
            public int C;
            public SC(int s, int c)
            {
                S = s;
                C = c;
            }

            public override string ToString()
            {
                return $"S:{S}, C:{C}";
            }
        }

        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var N = int.Parse(nm[0]);
            var M = int.Parse(nm[1]);
            var SCs = new List<SC>();
            for (var i = 0; i < M; i++)
            {
                var sc = Console.ReadLine().Split(' ');
                SCs.Add(new SC(int.Parse(sc[0]), int.Parse(sc[1])));
            }

            var min = (int)Math.Pow(10, N - 1);
            min = (min == 1) ? 0 : min;
            var max = (int)Math.Pow(10, N) - 1;

            var ans = -1;
            for (var i = min; i < max; i++)
            {
                var aok = true;
                foreach (var sc in SCs)
                {
                    var colS = GetColS(i, sc.S, N);
                    if (colS != sc.C)
                    {
                        aok = false;
                        break;
                    }
                }
                if (aok)
                {
                    ans = i;
                    break;
                }
            }
            Console.WriteLine(ans);
        }

        private static int GetColS(int value, int s, int N)
        {
            var ret = -1;
            var i = 0;
            for (var p = (int)Math.Pow(10, N - 1); 1 <= p; p = p / 10)
            {
                i++;
                if (i == s)
                {
                    ret = (value / p) % 10;
                    break;
                }
            }
            return ret;
        }
    }
}