using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadIntArray();

            IList<int[]> pairs = new List<int[]>();
            for (int i = 0; i < nm[1]; i++)
            {
                var r = ReadIntArray();
                pairs.Add(new int[]{r[0],r[1]});
            }

            for (int i = 1; i < 1000; i++)
            {
                if (i.ToString().Length < nm[0])
                {
                    continue;
                }
                if (pairs.All(item => item[0] <= i.ToString().Length &&
                                      i.ToString()[item[0] - 1].ToString() == item[1].ToString()))
                {
                    Console.WriteLine(i.ToString());
                    return;
                }
            }

            Console.WriteLine(-1);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}