using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {

            var data = Console.ReadLine().Split();
            var n = int.Parse(data[0]);
            var m = int.Parse(data[1]);
            var s = new List<int>();
            var c = new List<char>();
            string ans = "-1";
            bool judge = true;

            if (m != 0)
            {
                for (int i = 0; i < m; i++)
                {
                    var data2 = Console.ReadLine().Split();
                    s.Add(int.Parse(data2[0]));
                    c.Add(char.Parse(data2[1]));

                }

                if (n == 1)
                {

                    ans = "" + c[0];
                    for (int j = 0; j < m; j++)
                    {

                        if (c[j] != c[0]) ans = "-1";
                    }

                }

                if (n == 2)
                {
                    for (int i = 1; i < 10; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            judge = true;
                            var num = "" + i + "" + j;

                            for (int k = 0; k < m; k++)
                            {
                                if (num[s[k] - 1] != c[k]) judge = false;
                            }
                            if (judge)
                            {
                                ans = num;
                                break;
                            }
                        }
                        if (judge) break;
                    }
                }

                if (n == 3)
                {
                    for (int h = 1; h < 10; h++)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            for (int j = 0; j < 10; j++)
                            {
                                judge = true;
                                var num = "" + h + "" + i + "" + j;

                                for (int k = 0; k < m; k++)
                                {
                                    if (num[s[k] - 1] != c[k]) judge = false;
                                }
                                if (judge)
                                {
                                    ans = num;
                                    break;
                                }
                            }
                            if (judge) break;
                        }
                        if (judge) break;
                    }
                }
            }

            if (m == 0)
            {
                if (n == 1)
                {
                    ans = "0";
                }else if (n == 2)
                {
                    ans = "10";
                }
                else
                {
                    ans = "100";
                }
            }



            Console.WriteLine(ans);
        
            
        }
    }
}


Measured memory_bytes: 13268