using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtcoderExpress
{


    class Program
    {

        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = NK[0];
            var M = NK[1];
            var S = new int[M];
            var C = new char[M];
            for (int i = 0; i < M; i++)
            {
                var SC = Console.ReadLine().Split(' ').ToArray();
                S[i] = int.Parse(SC[0]);
                C[i] = (char)SC[1][0];
                // Console.WriteLine(C[i]);
            }
            long ans = -1;
            var flag = true;

            for (int i = (N == 1 ? 0 : (int)Math.Pow(10, N - 1)); flag && i < (int)Math.Pow(10, N); i++)
            {
                if (!flag)
                {
                    break;
                }
                var str = i.ToString();

                for (int j = 0; j < M; j++)
                {
                    var S1 = S[j] - 1;
                    var C1 = C[j];

                    if (str[S1] != C1)
                    {
                        break;
                    }

                    if (j == M - 1)
                    {
                        ans = i;
                        flag = false;
                    }
                }
            }
            Console.WriteLine(ans);
        }


    }
}
