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

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            if (m == 0)
            {
                Console.WriteLine("-1");
            }
            List<int[]> conditions = new List<int[]>();
            for(int i = 0; i < m; i++)
            {
                var sc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                conditions.Add(sc);
            }
            var ans = -1;

            var begin = n == 1 ? 1 : n == 2 ? 10 : 100;
            var end = n == 1 ? 9 : n == 2 ? 99 : 999;

            for (int i = begin; i <= end; i++)
            {
                var count = 0;
                foreach(var sc in conditions)
                {
                    if (sc[0] == 1 && sc[1] == i / 100
                        || sc[0] == 2 && sc[1] == (i % 100) / 10
                        || sc[0] == 3 && sc[1] == i % 10)
                    {
                        count++;
                    }
                }
                if (count == m)
                {
                    ans = i;
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}
