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

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nm = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var tmp = new int[nm[0]];
            for (var i = 0; i < tmp.Length; i++)
            {
                tmp[i] = 10;
            }

            for (var i = 0; i < nm[1]; i++)
            {
                var sc = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                if (tmp[sc[0] - 1] > sc[1])
                    tmp[sc[0] - 1] = sc[1];
            }

            for (var i = 0; i < tmp.Length; i++)
            {
                if (tmp[i] == 10)
                    tmp[i] = 0;
            }

            var result = int.Parse(string.Join("", tmp));
            Console.WriteLine((result.ToString().Length == nm[0]) ? result : -1);
        }
    }
}
