using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC157C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];

            var scList = new List<Tuple<int, int>>(M);
            for (var i = 0; i < M; i++)
            {
                var sc = Console.ReadLine().Split().Select(int.Parse).ToArray();
                scList.Add(Tuple.Create(sc[0], sc[1]));
            }

            if (scList.Any(x => x.Item1 == 1 && x.Item2 == 0))
            {
                Console.WriteLine("-1");
                return;
            }

            var ans = new int[N];
            foreach (var scs in scList.OrderByDescending(x => x.Item1).GroupBy(x => x.Item1))
            {
                if (scs.Distinct().Count() != 1)
                {
                    Console.WriteLine("-1");
                    return;
                }

                var sc = scs.First();
                ans[sc.Item1 - 1] = sc.Item2;
            }

            Console.WriteLine(int.Parse(string.Join("", ans)));
        }
    }
}
