using System;
using System.Linq;

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

            int[] si = new int[NM[1]];
            int[] ci = new int[NM[1]];

            int[] ans = new int[NM[0]];
            for (int i = 0; i < ans.Length; i++)
            {
                ans[i] = -1;
            }

            bool exist = true;
            for (int i = 0; i < NM[1]; i++)
            {
                var sc = Console.ReadLine().Split().Select(int.Parse).ToArray();
                si[i] = sc[0] - 1;
                ci[i] = sc[1];

                //存在しない条件
                if (si[i] == 0 && ci[i] == 0)
                    exist = false;

                if (ans[si[i]] == -1 || ans[si[i]] == ci[i])
                {
                    //更新
                    ans[si[i]] = (char)ci[i];
                }
                else
                    //存在しない条件
                    exist = false;
            }

            if (ans[0] == -1) ans[0] = 1;
            for (int i = 1; i < ans.Length; i++)
            {
                if (ans[i] == -1) ans[i] = 0;
            }

            string a = "";
            foreach (int s in ans) a += s;
            if (exist) Console.WriteLine(a);
            else Console.WriteLine("-1");
        }
    }
}
