using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public class Condition
        {
            public int S { get; set; }
            public int C { get; set; }
        }

        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = items[0];
            var M = items[1];

            var table = new List<Condition>();
            foreach (var i in Enumerable.Range(0, M))
            {
                var items2 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
                var s = items2[0];
                var c = items2[1];
                table.Add(new Condition { S = s, C = c });
            }

            var answer = -1;
            int min;
            int max;
            switch (N)
            {
                case 1:
                    min = 0;
                    max = 9;
                    break;
                case 2:
                    min = 10;
                    max = 99;
                    break;
                case 3:
                    min = 100;
                    max = 999;
                    break;
                default:
                    throw new Exception("エラー");
            }

            foreach (var num in Enumerable.Range(min, max - min + 1))
            {
                var checkText = num.ToString("000");
                if (table.Any(pair => checkText[pair.S - 1].ToString() != pair.C.ToString()))
                {
                    continue;
                }
                else
                {
                    answer = num;
                    break;
                }
            }

            Console.WriteLine(answer);
        }
    }
}
